My data includes data on different people ( ID) for each Dayweek and time they spend in different areas of the hospital or Ward. This time is given to me, in minutes: seconds or Duration. An example of my data is:
ShiftData <- data.frame(ID = c("Nelson", "Nelson", "Nelson", "Nelson", "Nelson",
"Justin", "Justin", "Justin", "Justin", "Justin",
"Nelson", "Nelson", "Nelson", "Nelson", "Nelson",
"Justin", "Justin", "Justin", "Justin", "Justin"),
Day = c("Monday", "Monday", "Monday", "Monday", "Monday",
"Monday", "Monday", "Monday", "Monday", "Monday",
"Tuesday", "Tuesday", "Tuesday", "Tuesday", "Tuesday",
"Tuesday", "Tuesday", "Tuesday", "Tuesday", "Tuesday"),
Ward = c("Gen", "Anaesth", "Front Desk", "PreOp", "Front Desk",
"PreOp", "Front Desk", "Anaesth", "Front Desk", "Gen",
"Gen", "Anaesth", "PreOp", "Front Desk", "Gen",
"Front Desk", "PreOp", "PostOp", "Front Desk", "Anaesth"),
Duration = c("5:35", "4:08", "4:30", "6:33", "4:17",
"15:35", "4:28", "9:37", "18:33", "4:20",
"9:45", "8:28", "6:37", "2:34", "4:27",
"19:35", "4:20", "9:47", "11:33", "4:26"))
First, I want to include a column that indicates when each IDwas on rotation or shift. A "Front Desk"in the column Wardindicates when a person changes his shift. A person can start with "Front Desk", regulated by how many hours they work the day before (this calculation is not required for the current analysis). My expected result would be:
ShiftData$Shift <- c(1,1,0,2,0,
1,0,2,0,3,
1,1,1,0,2,
0,1,1,0,2)
, , "Front Desk" 0 , .
?
, 0 "Front Desk", :
ShiftData$Shift <- ifelse(ShiftData$Ward=='Front Desk', 0, NA)
, ?