My data includes data on different people (ID
) over each Day
of the week and the time they spend in different areas of the hospital or Ward
. I am given this time, 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"))
I first wish to include a column that indicates when each ID
was on a rotation or shift. A "Front Desk"
in the Ward
column indicates when a person alters their shift. A person may start on "Front Desk"
, regulated by how many hours they work the day before (this calculation not required for the current analysis). My anticipated output 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)
My question is similar to this question except when there is a "Front Desk"
I want a 0 and any activity afterward, to count sequentially up.
How do I please create this?
I know that I can include a 0 for "Front Desk"
using:
ShiftData$Shift <- ifelse(ShiftData$Ward=='Front Desk', 0, NA)
But I am unsure how to include a sequential count for every other part of the column?