Reputation: 123
I want to convert a data table containing numeric values for 305 variables and 361 observations into a data table of same size containing dates. The data table does contain "NA"s.
The numeric value of the dates has the origin of excel. This is what I tried so far:
Rep_Day_monthly <- as.data.table(sapply(Rep_Day_monthly,as.numeric))
Rep_Day_monthly <- sapply(Rep_Day_monthly,as.Date)
Problem with this is, that the data table still contains numeric values, so e.g. 5963 instead of 1986-04-30.
Looking very much forward to your help!
Cheers
Upvotes: 0
Views: 649
Reputation: 18425
as.Date
needs an origin (i.e. a date corresponding to 0). If the data is from Excel, this will usually be 1 Jan 1970, so you could use Rep_Day_monthly <- as.data.table(lapply(Rep_Day_monthly,as.Date,origin="1970-01-01"))
Upvotes: 3