[Rd] strange behaviour in R 2.0.0 (PR#7275)

Gabor Grothendieck ggrothendieck at myway.com
Sun Oct 10 18:15:09 CEST 2004


 <xiao.gang.fan1 <at> libertysurf.fr> writes:

> 
> Full_Name: Xiao Gang FAN
> Version: R 2.0.0
> OS: Windows
> Submission from: (NULL) (82.226.247.142)
> 
> The following codes worked for R 1.9.1
> 
> > a = data.frame(x=1:2)
> > a$y = strptime(c("20010101","20020101"),"%Y%m%d")
> 
> this no longer works for R 2.0.0:
> 
> Error in "$<-.data.frame"(`*tmp*`, "y", value = list(sec = c(0, 0), min = c
(0, 
> : 
>         replacement has 9 rows, data has 2

Normally if one wants to store a POSIXt object in a data frame, one uses
POSIXct, not POSIXlt:

a <- data.frame(x = 1:2)
a$y <- as.POSIXct(strptime(c("20010101","20020101"),"%Y%m%d"))

Actually in this instance you are not using times at all so you
might be better off using the simpler Date class:

a <- data.frame(x = 1:2)
a$y <- as.Date(c("20010101","20020101"),"%Y%m%d")



More information about the R-devel mailing list