0

after loading a table from R, I need to convert several variables in useful data. Let's say the column I want to change's name is mydata[[2]][6]. This list has char data, for instance "42255.7298611111", and according to Openoffice, that value corresponds with 08/09/2015 17:31:00.

As far as I've seen, in other variables like mydata[[2]][3], where data is just for dates, data "42260" is easily converted to 09/14/2015 just by using:

mydata[[2]][3]  <- list(as.Date(strtoi(unlist(mydata[[2]][3])), origin="1900-01-01"))

Any guess about how to solve date-time problem?

Thanks in advanced! :)

1 Answers1

1

I don't have Open office here, so I used excel instead.

You could use the following function:

function(t) as.POSIXct((t-1)*86400, origin="1900-01-01", tz="GMT")

(the t-1 is because excel seems to think that origin=1900-01-00, but that is not allowed in R, 86400 is the number of seconds in a day since as.POSIXct is expecting seconds since origin as argument).

This will however give an error of one day, which I think I have tracked down to day 60 (which according to excel is 1900-02-29, but as far as I can see 1900 was not a leap year). To fix this I guess that you could take t-2 instead (at least if you are not concerned with dates that old).

DGKarlsson
  • 1,091
  • 12
  • 18