[R] converting multiple columns from POSIX* to Date
Farrel Buchinsky
fjbuch at gmail.com
Fri Dec 12 17:53:20 CET 2008
I got the whole thing to work, with Hadley Wickham's help.
is.POSIXt <- function(x) inherits(x, "POSIXt")
dates <- sapply(df, is.POSIXt)
df[dates] <-lapply(df[dates], as.Date)
Farrel Buchinsky
On Fri, Dec 12, 2008 at 11:26, Farrel Buchinsky <fjbuch at gmail.com> wrote:
>
> Something strange. The lapply only processed the first row and then wrote that value to every row of the original dataframe. It is as if the lapply is indeed processing every item on the list, namely each column, but the ifelse or the as.Date is getting messed up. Not only is it only processing the first row but it is also returning the value as numbers rather than dates. I am now playing around with Hadley Wickham's plyr package. So far looking good but still need to work out a few things.
More information about the R-help
mailing list