tapply and factors in R-0.61

Douglas Bates bates@stat.wisc.edu
Tue, 6 Jan 1998 09:55:41 -0600 (CST)

```Somehow it seems that tapply converts factors given as the _first_
argument to a numerical representation without the old factor levels.

> unlist(lapply(Machines, data.class))
Worker   Machine     score
"ordered"  "factor" "numeric"
> Machines[ 1:10, ]
Grouped Data: score ~ 1 | Worker
Worker Machine score
1       1       A  52.0
2       1       A  52.8
3       1       A  53.1
4       2       A  51.8
5       2       A  52.8
6       2       A  53.1
7       3       A  60.0
8       3       A  60.2
9       3       A  58.4
10      4       A  51.1
> tapply( Machines\$Machine, Machines\$Worker, function(x) x )
\$6
[1] 1 1 1 2 2 2 3 3 3

\$2
[1] 1 1 1 2 2 2 3 3 3

\$4
[1] 1 1 1 2 2 2 3 3 3

\$1
[1] 1 1 1 2 2 2 3 3 3

\$3
[1] 1 1 1 2 2 2 3 3 3

\$5
[1] 1 1 1 2 2 2 3 3 3

> tapply( Machines\$Machine, Machines\$Worker, data.class )
6        2        4        1        3        5
"factor" "factor" "factor" "factor" "factor" "factor"
> tapply( Machines\$Machine, Machines\$Worker, levels )
\$6
character(0)

\$2
character(0)

\$4
character(0)

\$1
character(0)

\$3
character(0)

\$5
character(0)
> levels( Machines\$Machine )
[1] "A" "B" "C"

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```