[R] Strange output daply with empty strata

hadley wickham h.wickham at gmail.com
Thu Sep 9 15:58:26 CEST 2010


> daply(data.test, .(municipality, employed), function(d){mean(d$age)} )
>             employed
> municipality       no      yes
>            A 41.58759 44.67463
>            B 55.57407 43.82545
>            C 43.59330       NA
>
> The .drop argument has a different meaning in daply. Some R functions have
> an na.last argument, and it may be that somewhere in daply, there is a
> function call that moves all NAs to the end. The means are in the right
> order except for the first, where the NA is supposed to be, so everything is
> offset in the table by 1. I've cc'ed Hadley on this.

This is a bug, which I've fixed in the development version (hopefully
to be released next week).
In the plyr 1.2:

> daply(data.test, .(municipality, employed), function(d){mean(d$age)} )
            employed
municipality       no      yes
           A       NA 39.49980
           B 44.69291 51.63733
           C 57.38072 45.28978

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list