I am having trouble (likely because I am new to dplyr) trying to recode values. I am trying to split participants up by number, then recode the day value as 1 and so on. Currently it is day of the month.... my goal is to make it day of experiment. Note: The first date listed for a participant should be day 1 for them.
My attempt:
df<-data.frame(participant_number=c(1,1,1,2,2),month=c(3,3,4,3,3),day=c(6,6,1,7,8))
res<-setDT(df) %>% group_by(participant_number) %>% day
My goal:
participant_number day month recoded_day
1 6 3 1
1 6 3 1
1 1 4 2
2 7 3 1
2 8 3 2