[R] Lost in POSIX

Dimitri Shvorob dimitri.shvorob at gmail.com
Sat Dec 25 22:39:35 CET 2010


.. One issue with the solution proposed by Jeff is that the transformed
column does not have the original's type:

> x = structure(list(time = structure(c(1020232904.818, 1020232904.818
), class = c("POSIXt", "POSIXct"), tzone = ""), price = c(321, 
323.5), minute = c(1020232860, 1020232860)), .Names = c("time", 
"price", "minute"), row.names = 1:2, class = "data.frame")

minute <- function(t)
{ 
  d <- as.POSIXlt(t, origin = as.Date("1970-01-01")) 
  d$sec <- 0 
  as.POSIXct(d) 
} 

> x$minute = sapply(x$time, minute)  

> head(x)
                 time price     minute
1 2002-05-01 07:01:44 321.0 1020232860
2 2002-05-01 07:01:44 323.5 1020232860

> class(x.l$minute)
[1] "numeric"

-- 
View this message in context: http://r.789695.n4.nabble.com/Lost-in-POSIX-tp3052768p3163969.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list