[R] expand.grid and the first level of a factor

Giovanni Marchetti gmm at ds.unifi.it
Sat May 3 14:53:23 CEST 2003


I do not understand this behaviour of expand.grid:

> expand.grid(x = c("b", "a"), y = c(1, 2))$x
[1] b a b a
Levels: b a
> expand.grid(x = c("b", "a"))$x
[1] b a
Levels: a b

Why the first level of the factor x depends on the number
of arguments of expand.grid? Apparently, I can set 
the order of the levels only when the number of 
arguments in > 1. In the second example, the order 
is lexicographic.

-- Giovanni
-- 
< Giovanni M. Marchetti >
Dipartimento di Statistica, Univ. di Firenze   Phone:  +39 055 4237 204
viale Morgagni, 59                             Fax:    +39 055 4223 560
I 50134 Firenze, Italy                         email:  gmm at ds.unifi.it



More information about the R-help mailing list