[R] Odd behavior of strptime

David Khabie-Zeitoune dave at evocapital.com
Thu May 29 17:26:38 CEST 2003


The strptime object is a structured list object with 9 components. (Type
"names(z)" to see the names of the individual components). You may want
to convert the strptime object to a POSIXct object using

Z = as.POSIXct(z)

This is just a vector (of the expected length).

Cheers,
Dave




-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
partha_bagchi at hgsi.com
Sent: 29 May 2003 16:05
To: r-help at stat.math.ethz.ch
Subject: [R] Odd behavior of strptime


The example from the help page for strptime has the following oddity:

>      dates <- c("02/27/92", "02/27/92", "01/14/92",
+                 "02/28/92", "02/01/92")
>      times <- c("23:03:20", "22:29:56", "01:03:30",
+                 "18:21:03", "16:56:26")
>      x <- paste(dates, times)
>      z <- strptime(x, "%m/%d/%y %H:%M:%S")
>      z
[1] "1992-02-27 23:03:20" "1992-02-27 22:29:56" "1992-01-14 01:03:30" 
"1992-02-28 18:21:03" "1992-02-01 16:56:26"
> 
> length(z)
[1] 9
>
The length is always denoted as 9.
Of course this implies that any replacement I want to do with dates etc.

always fails with the error:

Error in "[[<-.data.frame"(*tmp*, D[I], value = 
strptime(as.character(x[[D[I]]]),  : 
        replacement has 9 rows, data has 5970
>
> version
         _ 
platform i386-pc-mingw32
arch     i386 
os       mingw32 
system   i386, mingw32 
status 
major    1 
minor    7.0 
year     2003 
month    04 
day      16 
language R 
>
(platform Win2000 professional)

Has anyone else encountered this?

Thanks,
Partha.


	[[alternate HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list