[R] Date/Time to date & time

Mark Knecht markknecht at gmail.com
Sun Sep 20 22:11:18 CEST 2009


Hi,
    Can strptime (or some other function) help me turn the following
column of a data.frame into two new columns, one as date and the other
as time, preserving the AM/PM value?

Thanks,
Mark

> B
              ENTRY DATE
1  3/23/2009 6:30:00 AM
2  3/23/2009 6:30:00 AM
3  3/23/2009 6:39:00 AM
4  3/23/2009 6:39:00 AM
5  3/23/2009 6:48:00 AM
6  3/23/2009 6:48:00 AM
7  3/23/2009 7:00:00 AM

> strftime(B, tz="", format="%m/%d/%Y %I:%M:%s %p")
Error in as.POSIXlt.default(x, tz = tz) :
  do not know how to convert 'x' to class "POSIXlt"
>

> strptime(B, format="%m/%d/%Y %I:%M:%s %p")
[1] NA
>

> mode(B)
[1] "list"
> class(B)
[1] "data.frame"
>




More information about the R-help mailing list