[R] Problem using strptime

jim holtman jholtman at gmail.com
Thu Jul 16 13:45:19 CEST 2009


You need to use %Y (upper case) for YYYY

> z=strptime( "07/14/2009 13:41:00","%m/%d/%Y %H:%M")
>
> z
[1] "2009-07-14 13:41:00"
>


On Wed, Jul 15, 2009 at 11:45 PM, Alon Ben-Ari<alon.benari at gmail.com> wrote:
> Hello
> I am trying to read a date and time from a file and convert them to POSIXct
> using strptime()
> the dates are stored in t which is a factor
> This the code I am using  to illustarte
>
>> t[1]
> [1] 07/14/2009 13:41:00
> 10 Levels: 07/14/2009 13:41:00 07/14/2009 13:42:00 ... 07/15/2009 07:12:00
>> a=t[1]
>> a
> [1] 07/14/2009 13:41:00
> 10 Levels: 07/14/2009 13:41:00 07/14/2009 13:42:00 ... 07/15/2009 07:12:00
>> a=t[[1]]
>> a
> [1] 07/14/2009 13:41:00
> 10 Levels: 07/14/2009 13:41:00 07/14/2009 13:42:00 ... 07/15/2009 07:12:00
>> as.character(a)
> [1] "07/14/2009 13:41:00"
>> z=strptime(a,"%m/%d/%y %H:%M")
>> z
> [1] NA
>> z=strptime("07/14/2009 13:41:00","%m/%d/%y %H:%M")
>> z
> [1] NA
> Why do I get NA?
> I am running R 2.8, openSUSE  11.0
>
> Thanks
>
> Alon Ben-Ari
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list