I want to add a column of days each week to my dataset which contains continuous days and continuous weeks already for a large dataset
I've tried to use the floor function and the rep function already
Edit I'm attempting to automate the final output mydata$day_of_week
time_in_hrs<-c(0,2,12,24,25,29,30,32,38,43,57,82,93,105,199,205,245,263)
mydata<-as.data.frame(time_in_hrs)
mydata$time_in_days<-floor(mydata$time_in_hrs/24)+1
mydata$time_in_weeks<-floor(mydata$time_in_days/8)+1
mydata$day_of_week<-c(1,1,1,2,2,2,2,2,2,2,3,4,4,5,2,2,4,4)
Assuming you're trying to automate the column mydata$day_of_week
that you're now doing manually, you can do this as follows:
mydata$day_of_week_auto <- mydata$time_in_days - (mydata$time_in_weeks - 1) * 7