[R] reduce levels

Claus Atzenbeck claus.atzenbeck at freenet.de
Tue Nov 8 00:52:04 CET 2005


Hi all:

I have an example that shows my problem:

    > test <- data.frame(c("a", "b", "c"))
    > colnames(test) <- "mm"
    > sub <- subset(test, mm=="b")
    > sub$mm
    [1] b
    Levels: a b c
    > levels(sub$mm)
    [1] "a" "b" "c"

How can I reduce the levels to exclusively those which are part of the
data frame? That is in the above named example exclusively "b".

Reason: I want to iterate exclusively through those levels that exist
within a subset, but leave away all others.

Thanks for any hint.
Claus




More information about the R-help mailing list