MulaiMulai sekarang secara gratis

Importing and joining the accident data

It's the final chapter! Congratulations on making it this far. This chapter's scenario is that a senior executive believes that workplace accidents have increased this past year at the production sites. She wants you to find out if that's true, and if it is, to look into what might be driving the increase.

Start by importing the HR and accident datasets. Then join them together, and add a had_accident variable to make it easier to analyze accident rates.

Latihan ini adalah bagian dari kursus

HR Analytics: Exploring Employee Data in R

Lihat Kursus

Petunjuk latihan

  • Import "hr_data_2.csv" and "accident_data.csv" with read_csv(). Assign them to hr_data and accident_data, respectively.
  • Use left_join() to add the accident data to the HR data. Join on both employee ID and year.
  • Using %>% after the join, use mutate() to add had_accident, which is 0 when accident_type is NA, and 1 otherwise.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Load the packages
library(readr)
library(dplyr)

# Import the data 
hr_data <- ___
accident_data <- ___

# Create hr_joined with left_join() and mutate()
hr_joined <- ___ %>% 
  mutate(___) 
  
hr_joined
Edit dan Jalankan Kode