R語(yǔ)言中使用subset()和while取子集,你會(huì)發(fā)現(xiàn)子集的因子水平數(shù)沒(méi)有改變蝉揍。
那么問(wèn)題來(lái)了趋箩,對(duì)子集用table()怎么才能去掉未使用的因子?
droplevels()
可以將未使用的因子水平從一個(gè)因子或者一個(gè)數(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