Reputation: 181
I am trying to convert the odd columns of a dataframe to a POSIXct format.
My problem is the following one. If I run this:
as.POSIXct(timestamptest2[2,1])
I got the desired format:
"2018-05-01 15:00:16 CEST"
However when I am doing the conversion to all the columns I get this error:
as.POSIXct(timestamptest2[,odd_indexes])
Error in as.POSIXct.default(timestamptest2[, odd_indexes]) :
do not know how to convert 'timestamptest2[, odd_indexes]' to class “POSIXct”
Being odd_indexes a vector containing the colums date have my date in string format.
I have tried as well with:
-apply(timestamptest2[,odd_indexes],2,as.POSIXct)
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
Anyone knows how to deal with this problem?
Upvotes: 0
Views: 106
Reputation: 57686
This should work:
timestamptest2[odd_indexes] <- lapply(timestamptest2[odd_indexes], as.POSIXct)
Upvotes: 2