Dear all

I was willing to use argument 'exclude' in function xtabs to remove some
levels of factors (xtabs help page says '"exclude: a vector of values to be
excluded when forming the set of levels of the classifying factors").


I tried:

> mydata <- data.frame(
     treatment = c("B", "A", "C", "C", "B", "B", "C", "A", "B", "B", NA,
"C"),
     surv = c("YES", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "YES",
"NO", "NO", NA)
    )

> levels(mydata$treatment)
[1] "A" "B" "C"

> # try to remove level "B" in variable treatment
> xtabs(formula = ~ treatment + surv, data = mydata, exclude = "B")
        surv
treatment NO YES
       A  1   1
       B  3   2
       C  1   2



One alternative is to do:

> xtabs(formula = ~ treatment + surv, data = mydata[mydata$treatment != "B",
], drop.unused.levels = TRUE)
        surv
treatment NO YES
       A  1   1
       C  1   2



But I don't understand why I cannot remove "B" directly with argument
exclude.

Any help is welcome

Regards

Matthieu





My version on Windows XP

platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          9.0
year           2009
month          04
day            17
svn rev        48333
language       R
version.string R version 2.9.0 (2009-04-17)





------------------
Matthieu Lesnoff
CIRAD
Bamako, Mali
E-mail: matthieu.lesn...@cirad.fr

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to