  Hi,

I agree with you that levels should not be automatically dropped after 
subsetting.

However, I think there should/can be an extra argument to make it 
possible (the default being no dropping). I have no example in mind, but 
I guess it is possible that sometimes, one want to show only some 
levels. Would it be a bad approach?

Anyway, it is not that complicated to use factor() again.

Ivan

Le 9/21/2010 23:22, Greg Snow a écrit :
> This comes up every now and then.  The fact is that the behavior of R in not throwing away information unless explicitly told to, is a feature, and one that I don't want to see go away.
>
> Yes in your example doing a table or plot based on iris1$Species gives meaningless results, but anything you do with that column in now meaningless, why do you care if there is extra information in a column that you should not be doing anything further with anyways?  Does it really make sense to use that column for anything now?  It is a bit like a teacher bemoaning the fact that half of his/her students scored below the class median.
>
> Now some proposes that all factors should have levels dropped after subsetting, this is worse than useless, consider the following made up example:
>
> tmp1<- rep( c(1:5,1:5), c(10,20,30,20,0,0,10,20,30,20) )
> result<- factor(tmp1, levels=1:5, labels=c('Strongly Disagree',
> 	'Disagree', 'No Opinion', 'Agree', 'Strongly Agree') )
>
> my.df<- data.frame( result=result, sex = rep( c('M','F'), each=80 ) )
>
> df.m.2<- df.m.1<- my.df[ my.df$sex=='M', ]
> df.f.2<- df.f.1<- my.df[ my.df$sex=='F', ]
>
> df.m.1[]<- lapply( df.m.1, factor )
> df.f.1[]<- lapply( df.f.1, factor )
>
>
> dev.new()
> par(mfrow=c(2,1))
> barplot(table(df.m.1$result), main='Males')
> barplot(table(df.f.1$result), main='Females')
>
> dev.new()
> par(mfrow=c(2,1))
> barplot(table(df.m.2$result), main='Males')
> barplot(table(df.f.2$result), main='Females')
>
>
> Which pair of plots is more meaningful? Easier to read? Not misleading?
>
>
>

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra@uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php


	[[alternative HTML version deleted]]

