[Rd] aggregate() does not return POSIXct object correctly (PR#12887)

2008-09-16 Thread rene . locher
Full_Name: Rene Locher
Version: 2.7.2 Patched (2008-09-12 r46541)
OS: XP
Submission from: (NULL) (160.85.231.40)


dat - data.frame(event=factor(c(A,A,B)),
  time=as.POSIXct(c(2008-01-10,2008-01-01,2008-01-04)))

min(dat$time)
## 2008-01-01 CET
## as expected

aggregate(dat$time,by=list(event=dat$event),min)
## results in
##event  x
##  1 A 1199142000
##  2 B 1199401200

## I expected:
##eventx
##  1 A 2008-01-01 CET
##  2 B 2008-01-04 CET

## my system:

sessionInfo()
## R version 2.7.2 Patched (2008-09-12 r46541)
## i386-pc-mingw32
##
## locale:
## 
LC_COLLATE=German_Switzerland.1252;LC_CTYPE=German_Switzerland.1252;LC_MONETARY=German_Switzerland.1252;LC_NUMERIC=C;LC_TIME=German_Switzerland.1252
##
## attached base packages:
## [1] stats graphics  grDevices utils datasets  methods   base

Kind regards

Rene Locher E-Mail: [EMAIL PROTECTED]
Institute for Data Analysis and Process Design Tel:+41 58 934 7810
Zurich University of Applied Sciences  Fax:+41 58 935 7810
Rosenstrasse 3   
Postfach
CH-8401 Winterthurhttp://www.idp.zhaw.ch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] aggregate() does not return POSIXct object correctly (PR#12887)

2008-09-16 Thread Peter Dalgaard
[EMAIL PROTECTED] wrote:
 Full_Name: Rene Locher
 Version: 2.7.2 Patched (2008-09-12 r46541)
 OS: XP
 Submission from: (NULL) (160.85.231.40)


 dat - data.frame(event=factor(c(A,A,B)),
   time=as.POSIXct(c(2008-01-10,2008-01-01,2008-01-04)))

 min(dat$time)
 ## 2008-01-01 CET
 ## as expected

 aggregate(dat$time,by=list(event=dat$event),min)
 ## results in
 ##event  x
 ##  1 A 1199142000
 ##  2 B 1199401200

 ## I expected:
 ##eventx
 ##  1 A 2008-01-01 CET
 ##  2 B 2008-01-04 CET
   

This is as documented, possibly annoying, but not a bug.

aggregate() is documented to build on tapply() for which the discarding
of class is documented on ?tapply. The root cause is unlist():

 tapply(dat[[time]],dat$event,min,simplify=FALSE)
$A
[1] 2008-01-01 CET

$B
[1] 2008-01-04 CET

 unlist(tapply(dat[[time]],dat$event,min,simplify=FALSE))
 A  B
1199142000 1199401200

and a partial rationale is that unlist() wouldn't know what to do if the
arguments had different classes.
The workaround is, of course, just to stick the class back on.




-- 
   O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] aggregate() does not return POSIXct object correctly (PR#12887)

2008-09-16 Thread Gabor Grothendieck
On Tue, Sep 16, 2008 at 11:22 AM, Peter Dalgaard
[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
 Full_Name: Rene Locher
 Version: 2.7.2 Patched (2008-09-12 r46541)
 OS: XP
 Submission from: (NULL) (160.85.231.40)


 dat - data.frame(event=factor(c(A,A,B)),
   time=as.POSIXct(c(2008-01-10,2008-01-01,2008-01-04)))

 min(dat$time)
 ## 2008-01-01 CET
 ## as expected

 aggregate(dat$time,by=list(event=dat$event),min)
 ## results in
 ##event  x
 ##  1 A 1199142000
 ##  2 B 1199401200

 ## I expected:
 ##eventx
 ##  1 A 2008-01-01 CET
 ##  2 B 2008-01-04 CET


 This is as documented, possibly annoying, but not a bug.

 aggregate() is documented to build on tapply() for which the discarding
 of class is documented on ?tapply. The root cause is unlist():

 tapply(dat[[time]],dat$event,min,simplify=FALSE)
 $A
 [1] 2008-01-01 CET

 $B
 [1] 2008-01-04 CET

 unlist(tapply(dat[[time]],dat$event,min,simplify=FALSE))
 A  B
 1199142000 1199401200

 and a partial rationale is that unlist() wouldn't know what to do if the
 arguments had different classes.
 The workaround is, of course, just to stick the class back on.


Another workaround is:

https://stat.ethz.ch/pipermail/r-help/2008-September/173139.html

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel