The following code was working earlier, so I am not sure what went wrong! I was referring to this link to do something very similar [survival analysis - R Optimal way to create time series from start and end dates for groups - Stack Overflow]
The error occurs after running these 3 lines:
csuite <- csuite %>%
mutate(DateStartRole=ifelse(DateStartRole=="N", NA, DateStartRole)) %>%
mutate(DateStartRole = as.Date(DateStartRole, "%Y%m%d"))
This is the error:
Error: Problem with mutate()
input DateStartRole
.
x character string is not in a standard unambiguous format
Input DateStartRole
is ifelse(DateStartRole == "N", NA, DateStartRole)
.
I am also having the following two errors:
Here is the code:
range <- rbindlist(lapply(csuite(csuite$DateStartRole, csuite$DateEndRole, csuite$CompanyID),as.data.frame))
Here is the error:
Error in csuite(csuite$DateStartRole, csuite$DateEndRole, csuite$CompanyID) :
could not find function "csuite"
Here is the code:
csuite <- data.table(csuite)
csuite[,:=
("DateStartRole" = as.Date(DateStartRole), "DateEndRole" = as.Date(DateEndRole))]
csuite[,num_mons:= length(seq(from=DateStartRole, to=DateEndRole, by='month')),by=1:nrow(csuite)]
Here is the Error
Error in seq.int(r1$mon, 12 * (to0$year - r1$year) + to0$mon, by) :
'from' must be a finite number