I have the following R data frame:
ID Completed Days
001 Yes 65
002 No NA
003 Yes 120
004 Yes 22
I would like to create the following data set:
ID Month Success DaysAtSuccess
001 1 No NA
002 1 No NA
003 1 No NA
004 1 Yes 22
001 2 No NA
002 2 No NA
003 2 No NA
004 2 Yes 22
001 3 Yes 65
002 3 No NA
003 3 No NA
004 3 Yes 22
001 4 Yes 65
002 4 No NA
003 4 Yes 120
004 4 Yes 22
The idea is to have the 'Month' column enumerate by 30 days. For example, Month = 1 would include days 0-30, Month = 2 would include days 31-60, etc... The DaysAtSuccess would equal the value in the Day column if the value is equal to or greater than the lower value at each month. I am working on creating the data set using the mutate (dplyr) and ifelse functions but so far no luck. Any insight would be appreciated.
Edit:
Using the following code, I have been able to generate a 'Month' column:
df$Month <-ceiling(df$Days/30)
Which generates the following data set:
ID Completed Days Month
001 Yes 65 3
002 No NA NA
003 Yes 120 4
004 Yes 22 1
.? Is itNA?df$DaysAtSuccess <- df$Days*(df$Success == "Yes")*(cieling(df$Days/30) == df$month)?df$month <- ceiling(df$Days/30)?