I have a custom function ShiftType, which returns "Days" if the first value is D, A, P, "Nights" if it is N, and "Swing" if it is S. I am trying to apply this to a column in a dataframe (Roster$Shift.Pattern), with the code
Roster$Shift.Type<-apply(Roster$Shift.Pattern, 1, ShiftType)
, what should I change to not get this error and apply the function to each value in Shift.Pattern?
ShiftType <-function(x) {
if (substring(x, 1 ,1) == "D") {return("Days")}
else if (substring(x, 1 ,1) == "N") {return("Nights")}
else if (substring(x, 1 ,1) == "S") {return("Swing")}
else if (substring(x, 1 ,1) == "A") {return("Days")}
else if (substring(x, 1 ,1) == "P") {return("Days")}
else {return("None")}
}