On May 16, 2013, at 10:43 AM, Dominic Roye wrote:
> Hello,
>
> I'm a little surprised about the result of strftime for my data.
>
>> str(time)
> chr [1:315504] "2006-01-01 00:10:00" "2006-01-01
00:20:00" "2006-01-01
> 00:30:00" ...
>
>> str(strftime(time,format="%Y-%m-%d %H:%M:%S"))
> chr [1:315504] "2006-01-01 00:00:00" "2006-01-01
00:00:00" "2006-01-01
> 00:00:00" ...
>
> Why strftime is eliminating the hours?
What do you mean by "eliminating the hours"? You only showed us three
instances, none of which had anything other than "00" for the hours.
More fundamentally however, strftime() is designed to take POSIXt arguments
while you are sending it "character" arguments. Why would you want to
use strftime on character data anyway? I would argue that the expected result
from passing a character vector should be undefined.
>
>> str(strftime(time[1:500],format="%Y-%m-%d %H:%M:%S"))
> chr [1:500] "2006-01-01 00:10:00" "2006-01-01 00:20:00"
"2006-01-01
> 00:30:00" ...
>
> With less data, the time is correct. What is going on here?
I have found that giving erroneous data in the time section of just some of the
input will "zero out" all of the time values on my system (R 3.0.0 on
MacOSX 10.7.5):
dts <- c("2006-01-01 25:10:00", "2006-01-01 00:20:00",
"2006-01-01 00:30:00")
strftime(dts,format="%Y-%m-%d %H:%M:%S")
#[1] "2006-01-01 00:00:00" "2006-01-01 00:00:00"
"2006-01-01 00:00:00"
So my guess would be that you have impossible-to-format time data after the 500
mark. The help page says these behaviors are systemm-specific and you have not
suppled the requested details of you version or OS.
It would be better to submit a _small_ data object (not all of a 315504 element
vector) in a form that can reproducible, preferably the output from
dput(object).
--
David Winsemius
Alameda, CA, USA