You need the ISOdatetime() function:
R> mytimes <- ISOdatetime(2012,1,2,1,2,c(3.123,3.456,3.789),tz="UTC") R> mytimes [1] "2012-01-02 01:02:03.122 UTC" "2012-01-02 01:02:03.456 UTC" [3] "2012-01-02 01:02:03.789 UTC"
And these are the real POSIXct objects:
R> diff(mytimes) Time differences in secs [1] 0.333 0.333 attr(,"tzone") [1] "UTC" R>
I made my life easier for example and had only one argument, which was numbered. But with your data in the mydf variable, let's say you could do
mytimes <- with(mydf, ISOdatetime(Year, Month, Day, Hour, Min, Sec))
and you have to be tuned and ready to build. You can also assign the mytimes column mytimes original data.frame .
Dirk eddelbuettel
source share