[R] question about sorting POSIXt vector

Petr Pikal petr.pikal at precheza.cz
Thu Feb 10 09:22:52 CET 2005


Hi Bogdan

the behaviour is result of ct and lt POSIX class

try

> str(test)
`POSIXlt', format: chr [1:4] "2005-02-08 18:49:15" "2005-02-07 
18:36:54" "2005-02-04 18:37:03" "2005-02-06 18:29:04"
> str(tst)
`POSIXct', format: chr [1:4] "2005-02-08 18:49:15" "2005-02-07 
18:36:54" "2005-02-04 18:37:03" "2005-02-06 18:29:04"
>

or

> length(tst)
[1] 4
> length(test)
[1] 9
>

and read help pages about POSIX how to convert

Cheers
Petr


On 9 Feb 2005 at 17:38, bogdan romocea wrote:

> Dear useRs,
> 
> How come the first attempt to sort a POSIXt vector fails (Error:
> non-atomic type in greater), while the second succeeds? (Code inserted
> below.) The documentation says that POSIXt is used to allow operations
> such as subtraction, so I'd expect sorting to work. Is this perhaps an
> OS issue? (I run R 2.0.1 on Win xp.)
> 
> Thank you,
> b.
> 
> #------------code
> test <- c("2005-02-08 18:49:15","2005-02-07 18:36:54",
>  "2005-02-04 18:37:03","2005-02-06 18:29:04")
> test <- strptime(test,format="%Y-%m-%d %H:%M:%S")
> order(test,decreasing=F)	#doesn't work - why?
> tst <- test + 0
> order(tst,decreasing=F)	#works - how come?
> print(tst)
> #------------run
> > test <- c("2005-02-08 18:49:15","2005-02-07 18:36:54",
> + "2005-02-04 18:37:03","2005-02-06 18:29:04")
> > test <- strptime(test,format="%Y-%m-%d %H:%M:%S")
> > order(test,decreasing=F)#doesn't work - why?
> Error in order(test, decreasing = F) : non-atomic type in greater >
> tst <- test + 0 > order(tst,decreasing=F)#works - how come? [1] 3 4 2
> 1 > print(tst) [1] "2005-02-08 18:49:15 Eastern Standard Time"
> "2005-02-07 18:36:54 Eastern Standard Time" [3] "2005-02-04 18:37:03
> Eastern Standard Time" "2005-02-06 18:29:04 Eastern Standard Time" >
> 
> ______________________________________________
> 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