[R] Changing values (factors) does not change levels of that value?!

Philipp Pagel p.pagel at wzw.tum.de
Sun Nov 16 14:35:08 CET 2008


>  * when then looking at str(weblog),
>    the "-" will stay in the levels, mentioned for the variable weblog$V8
>    -> BAD!
> 
> Is this snormal behaviour?

Yes, it is. The idea is that a factor has a given set of levels
independent of how often you find them in your data - including
the case that a level is not observed at all. E.g. gender cn take
levels 'male' or 'female' but you may have a sample of females.

> Do I have to throw out the unwanted level by myself?

Yes, and it's easy:

> x <- factor(c('A','B','C','A','C'))
> y <- x[x!='C']
> y
[1] A B A
Levels: A B C
> factor(y)
[1] A B A
Levels: A B

cu
	Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel



More information about the R-help mailing list