You can use "drop=TRUE" as argument in indexing (brackets) to drop
unused levels, see the following example:
a <- factor(1:2, levels=1:3)
a
# [1] 1 2
# Levels: 1 2 3
for(i in levels(a)) print(i)
#[1] "1"
#[1] "2"
#[1] "3"
for(i in levels(a[, drop=TRUE])) print(i)
#[1] "1"
#[1] "2"
Uwe Ligges
Hi,
In a symmetric design one may have a data.frame with, say, two factors (two
columns), each one with n levels.
In a nested loop, to run a expression combining levels of each factors, to
produce a new data.frame, if one level is absent, the loop is interrupted;
one gets a empty object.
2 matches
Mail list logo