[R] Unable to understand strptime() behaviour

Petr Pikal petr.pikal at precheza.cz
Wed Dec 1 10:59:17 CET 2004


Hi Tim

On 1 Dec 2004 at 9:36, Tim Churches wrote:

> R V2.0.1 on Windows XP.
> 
> I have read the help pages on strptime() over and over, but can't
> understand why strptime() is producing the following results.
> 
>    > v <- format("2002-11-31", format="%Y-%m-%d")
>    > v
> [1] "2002-11-31"
>    > factor(v, levels=v)
> [1] 2002-11-31
> Levels: 2002-11-31
>    > x <- strptime("2002-11-31", format="%Y-%m-%d")
>    > x
> [1] "2002-12-01"
>    > factor(x, levels=x)
> [1] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
> Levels: 2002-12-01 NA NA NA NA NA NA NA NA


This is due to difference in POSIXlt and POSIXct
see

> length(factor(x, levels=x))
[1] 9
> y<-as.POSIXct(x)
> factor(y, levels=y)
[1] 2002-12-01
Levels: 2002-12-01

I do now the result but I do not now the intimate details about 
classes.

Cheers
Petr


> 
> Tim C
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list