[R] question about sorting POSIXt vector

bogdan romocea br44114 at yahoo.com
Thu Feb 10 02:38:30 CET 2005


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"
>




More information about the R-help mailing list