[R] Problem with strptime

R. Michael Weylandt michael.weylandt at gmail.com
Mon May 28 02:43:32 CEST 2012


Dates and times are notoriously tricky to get right and the fact that
the printed representation is so different from the internal (which is
basically just a count of seconds) doesn't really help: to make this
fully reproducible, could you supply us with the output of

dput(head(read.table("data1.txt",header=T,sep="\t"), 30))
dput(head(read.table("data2.txt",header=T,sep="\t"), 30))

as well?

Thanks!
Michael

On Sun, May 27, 2012 at 3:56 PM, Des Callaghan
<des.callaghan at ecostudy.co.uk> wrote:
> Hello Forum,
>
>
>
> I have a problem with the strptime function. With the 'data1' dataset below
> it works fine, but with the 'data2' dataset something goes wrong (see final
> line below). Both data1 and data2 are in exactly the same original format,
> the only difference is that they span different dates. Please help, since it
> is driving me nuts! Many thanks.
>
>
>
> Best wishes,
>
> Des
>
> -
>
>> data1=read.table("data1.txt",header=T,sep="\t")
>
>> datetime1=strptime(data1$Date, "%a %b %d %H:%M:%S %Y") #example line from
> data1 'Tue Aug 16 03:00:01 2011'
>
>> summary(datetime1)
>
>                     Min.                   1st Qu.
> Median                      Mean
>
> "2011-08-15 21:00:01 BST" "2011-10-08 01:00:01 BST" "2011-11-30 05:00:01
> GMT" "2011-11-30 04:38:47 GMT"
>
>                  3rd Qu.                      Max.
>
> "2012-01-22 09:00:01 GMT" "2012-03-15 13:00:01 GMT"
>
>> min(datetime1)
>
> [1] "2011-08-15 21:00:01 BST"
>
>> data2=read.table("data2.txt",header=T,sep="\t")
>
>> datetime2=strptime(data2$Date, "%a %b %d %H:%M:%S %Y") #example line from
> data2 'Sun Nov 27 13:07:01 2011'
>
>> summary(datetime2)
>
>                     Min.                   1st Qu.
> Median                      Mean
>
> "2011-11-27 01:07:01 GMT" "2012-01-09 20:07:01 GMT" "2012-02-22 15:07:01
> GMT" "2012-02-22 15:26:16 GMT"
>
>                  3rd Qu.                      Max.
>
> "2012-04-06 12:07:01 BST" "2012-05-20 07:07:01 BST"
>
>> min(datetime2)
>
> [1] NA
>
>
>
>
>
>
>
>
>
>
>        [[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.



More information about the R-help mailing list