R: Using sapply on vector of POSIXct

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-03-20T05:56:40Z Indexed on 2010/03/20 6:01 UTC
Read the original article Hit count: 273

Filed under:

I have what may be a very simple question. I want to process a column of POSIXct objects from a dataframe and generate a vector of datetime strings. I tried to use the following sapply call

dt <- sapply(df$datetime, function(x) format(x,"%Y-%m-%dT%H:%M:%S"))

but to no avail. I keep getting the following error

Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, : invalid 'trim' argument

When I apply this function to a single POSIXct object from the column, I have no problem. So I'm stumped at the moment about what the problem is. Do I need to do something special with POSIXct objects?

© Stack Overflow or respective owner

Related posts about r