[R] Tripped up by Removing Level

Jason Rupert jasonkrupert at yahoo.com
Thu Jul 30 02:47:37 CEST 2009


Code is provided below.

I was trying to follow the example at the following website:
http://www.ats.ucla.edu/stat/R/modules/factor_variables.htm

Only difference is that I am working with trying to remove a level from a dataframe.  In the example below, notice that "very.high" is still a level in bargin$stuffnew, even though I thought I removed it.  

Thanks for info on what I might have overlooked to remove "very.high" level and if I can do it after the fact from bargin$stuffnew.

Thanks again.

bargin<-NULL
ses<-NULL
ses <- c("low", "middle", "low", "low", "low", "low", "middle", "low", "middle", "middle", "middle", "middle", "middle", "high", "high", "low", "middle", "middle", "low", "high")
bargin$stuff <- factor(ses, levels = c("low", "middle", "high"))
bargin$stuff
bargin$stuff<-factor(bargin$stuff, levels = c(levels(bargin$stuff), "very.high"))
bargin$stuff
bargin$stuffnew<-bargin$stuff[bargin$stuff != "very.high"]
bargin$stuffnew
 [1] low    middle low    low    low    low    middle low    middle middle middle middle middle high  
[15] high   low    middle middle low    high  
Levels: low middle high very.high




More information about the R-help mailing list