0

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

Tobi1990
  • 105
  • 1
  • 10

1 Answers1

3

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"))

Andrew Gustar
  • 17,295
  • 1
  • 22
  • 32
  • Thanks, works fine! I already tried putting in the origin, though I had the wrong syntax.. Rep_Day_monthly <- as.data.table(lapply(Rep_Day_monthly,as.Date(,origin="1970-01-01"))) – Tobi1990 Mar 26 '17 at 09:50