I'm trying to recode a column to determine the shift of an employee.
The data is messy and the word I am looking for must be extracted from the text. I've been trying various routes with if
statements, stringr
and dplyr
packages, but can't figure out how to get them to work together.
I have this line of code, but str_match doesn't produce a true/false value.
Data$Shift <- if(str_match(Data$Unit, regex(first, ignore_case = TRUE))) {
print("First Shift")
} else {
print("Lame")
}
recode is working, but I have multiple values I need to recode and want to learn if there is a way to incorperate stringr into the recode function.
Data$Shift1 <- recode(Data$Unit, "1st" = "First Shift")
Currently, the text must be extracted from the column to contain 1st, First, or first for First Shift. My data looks like the Unit Column, and I want to Recode it into the Shift Column:
Unit Shift
Detention, Third Shift Third Shift
D, 3rd Shift Third Shift
1st First Shift
first shift First Shift
First Shift First Shift
1st shift First Shift
1st Shifft First Shift `