R語言中使用subset()和while取子集,你會發(fā)現(xiàn)子集的因子水平數(shù)沒有改變。
那么問題來了,對子集用table()怎么才能去掉未使用的因子?
droplevels()可以將未使用的因子水平從一個因子或者一個數(shù)據(jù)框中去掉。
The function droplevels is used to drop unused levels from a factor or, more commonly, from factors in a data frame.
在R中演示代碼如下:

subset().jpg