[R] Subsetting problem
mark_difford at yahoo.co.uk
Thu Jul 12 12:23:06 CEST 2007
Professor Ripley has given you your answer.
It may help you further to know that factor levels aren't automatically
dropped when you subset a data set; you have to do it manually. Some time
ago I scrounged the following command from Andy Liaw's randomForest package:
it removes all empty factor levels in a subsetted data set.
I subset a great deal, and find it extremely useful.
MyDat <- lapply(MyDat, function(x) if (is.factor(x)) x[, drop=T] else x)
## Liaw's code for doing this
On Thu, 12 Jul 2007, Cressoni, Massimo (NIH/NHLBI) [F] wrote:
> I need to perform the Exact Wilcoxon Mann-Whitney on a subset of my
> Assuming that IPPO is my data frame and IPPOBIS is the subset my variable
> have 3 different levels and the function wilcox_test (package "coin")
> does not accept it.
> I do not know how to overcome this problem.
> ippo <- c(rep("A",10),rep("B",10),rep("C",10))
> ippo2 <- c(rnorm(10,0,1),rnorm(10,10,10),rnorm(10,10,10))
> IPPO <- data.frame(ippo,ippo2)
> IPPOBIS <- IPPO[IPPO$ippo == "A" | IPPO$ippo == "B",]
> wilcox_test(ippo2 ~ ippo,data=IPPOBIS,distribution=exact())
> Error in check(itp) : 'object' does not represent a two sample problem
>  "A" "B" "C"
> Massimo Cressoni
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
View this message in context: http://www.nabble.com/Subsetting-problem-tf4066094.html#a11557188
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help