Hello
Quick question I hope.
I have a factor variable ("Treatment") in a data frame ("data") and I want to
extract rows for certain levels of Treatment and ignore the rest.
eg. levels for Treatment are "A", "B", "C", "D" and "E".
> levels(data$Treatment)
[1] "A" "B" "C" "D" "E"
I only want Treatments "B", "C" and "D", so I select create "newdata" thus;
newdata <- data[(data$Treatment=="B"|data$Treatment=="C"|data$Treatment=="D"),]
When I look at means for a response variable "Y" I get:
> tapply(Y, Treatment, mean)
A B C D E
NA 1460.274 1296.284 786.0946 NA
My question is: How do I get rid of the level names for "A" and "E" from the
variable "Treatment" in "newdata" (without using the GUI)?
(Using S+ 7.0 for Windows)
Many thanks
Mark Hearnden
Primary Industry Services
Department of Primary Industry, Fisheries and Mines
Northern Territory Government of Australia
GPO Box 3000
DARWIN NT 0801
Phone: (08) 899 92131
Fax: (08) 899 92010
Mob: 0401 115 857
"Everything should be made as simple as possible,
but not simpler." Albert Einstein.
|