[R] Help with simple as.POSIXlt or strptime

Jim Lemon jim at bitwrit.com.au
Sun Sep 29 04:12:28 CEST 2013


On 09/29/2013 01:27 AM, Leopoldo Catania wrote:
> Hi,
> I really don't know what is wrong with my code, I have a character object
> and I need to have a POSIXlt object; my code is:
>> date="Mon, 23 Sep 2013 06:45:05 GMT"
>> as.POSIXlt(date,format="%a, %d %b %Y %H:%M:%S %Z")
> [1] NA
> even with
>> strptime(date,"%a, %d %b %Y %H:%M:%S %Z")
> [1] NA
> Also if I remove "Mon," and "GMT"
>> date2="23 Sep 2013 06:45:05"
>> as.POSIXlt(date2,format="%d %b %Y %H:%M:%S")
> [1] NA
>> strptime(date2,format="%d %b %Y %H:%M:%S")
> [1] NA
> If I try to run the last code line in ?strptime the result is:
> ## An RFC 822 header (Eastern Canada, during DST)
> strptime("Tue, 23 Mar 2010 14:36:38 -0400",  "%a, %d %b %Y %H:%M:%S %z")
> [1] NA
>
Hi Leopoldo,
The %Z is only included in the format string for output. Try these:

strptime(date,"%a, %d %b %Y %H:%M:%S")
[1] "2013-09-23 06:45:05"
strptime(date,"%a, %d %b %Y %H:%M:%S",tz="GMT")
[1] "2013-09-23 06:45:05 GMT"

Jim



More information about the R-help mailing list