Tuesday, 6 August 2013

how do you pick the hour, minute and second from the posixct formated datetime in R

how do you pick the hour, minute and second from the posixct formated
datetime in R

I have a data frame like this:
dput(tail(x,10))
structure(list(DATE = structure(c(1375725600, 1375729200, 1375732800,
1375736400, 1375740000, 1375743600, 1375747200, 1375750800, 1375754400,
1375758000), class = c("POSIXct", "POSIXt"), tzone = ""), VOLUME =
c(2790797L,
2670868L, 2586397L, 2470043L, 2336334L, 2228206L, 2129270L, 2032518L,
872133L, 725377L), PC = c(10.12, 9.95, 9.9, 9.46, 8.99, 8.94,
9.79, 8.45, 8.85, 8.5)), .Names = c("DATE", "VOLUME", "PC"), row.names =
3399:3408, class = "data.frame")
I need to create another colume for time so that I can pick and choose
between different times in a day.
I have tried this:
x$time<-format(x$DATE, "%H:%M:%S)
did not work, I am getting empty values.
I also tried this:
x$t<-strptime(x$DATE, format="%H:%M:%S")
I get NA values. My x$DATE is formated as POSIXct, any ideas what might me
going on here?

No comments:

Post a Comment