paul sorenson
2006-Aug-11 23:25 UTC
[R] more on date conversion differences in 2.2.1 vs 2.3.1
With dates I get different results with 2.2.1 and 2.3.1. From my somewhat naive point point of view, the 2.2.1 behaviour seems more sensible. Running the code below in 2.2.1: V1 2006-08-01 2006-08-01 1 1 With 2.3.1 I get: V1 1154354400 1154440800 1 1 # testdate.R t <- read.csv2('testdate.csv', header=FALSE) t$V1 <- as.POSIXct(t$V1) print(t) x <- xtabs(V2 ~ V1, data=t) print(x) # testdate.csv 2006-8-1;0;1 2006-8-1;1;1 2006-8-2;0;1 2006-8-2;0;0 2006-8-2;1;1
Achim Zeileis
2006-Aug-12 00:22 UTC
[R] sort() for time/date objects (was: more on date conversion differences in 2.2.1 vs 2.3.1)
On Sat, 12 Aug 2006 09:25:10 +1000 paul sorenson wrote:> With dates I get different results with 2.2.1 and 2.3.1. From my > somewhat naive point point of view, the 2.2.1 behaviour seems more > sensible.Your example below does not really make the source of the problem obvious. I tried to see where the problem comes from and the following seems to happen: xtabs() calls factor() calls sort(unique()) for computing the levels And in the last step sort() seems to strip off the "class" attribute, leaving only the underlying numeric vector. Of course, the functions never claimed to work for "POSIXct" objects, hence you should call xtabs() appropriately, e.g. via xtabs(V2 ~ as.character(V1), data = t) However, it might be desirable to have sort() working for time/date objects (such as POSIXct, Date and date). sort() would just have to preserve the class as it did in R 2.2.1. Z> Running the code below in 2.2.1: > V1 > 2006-08-01 2006-08-01 > 1 1 > > With 2.3.1 I get: > V1 > 1154354400 1154440800 > 1 1 > > # testdate.R > t <- read.csv2('testdate.csv', header=FALSE) > t$V1 <- as.POSIXct(t$V1) > print(t) > x <- xtabs(V2 ~ V1, data=t) > print(x) > > # testdate.csv > 2006-8-1;0;1 > 2006-8-1;1;1 > 2006-8-2;0;1 > 2006-8-2;0;0 > 2006-8-2;1;1 > > ______________________________________________ > 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 and provide commented, > minimal, self-contained, reproducible code. >