Skip to content
Prev 170444 / 398503 Next

tapply bug? - levels of a factor in a data frame after tapply are intermixed

It comes down to 2 simple rules:

1. If you don't care about the order of the factor levels, then it doesn't matter how R codes the relationship
2. If you do care about the order, then tell R what order you want.  

Consider the following:
[1] 9  3  15 9  15 9  3 
Levels: 3 9 15
[1] 9  3  15 9  15 9  3 
Levels: 15 3 9
[1] 9  3  15 9  15 9  3 
Levels: 9 3 15

The last looks most like what you want, but for many uses, all 3 will give equivalent results.

Hope this helps,