I’m working with a factor of dates (dateframe$LastDate) brought in from the csv file and would like to calculate the days from today. Missing values are the norm with dates populating about 20% of 1000 rows.
Here’s what I have so far which is returning me the factor of days since 1970. It just feels like a lot of work to do a simple thing so I’m sure I’m off somewhere.
NumberOfDays <- ifelse(!is.na(LastDate), Sys.Date()-LastDate, as.numeric(""))
You need to make sure that LastDate is in date format initially. I’m not positive that as.numeric is required here.
If you want the NA’s to be zero, use