R语言-R包

R语言subset()函数取子集无法改变因子水平数

2014-10-25  本文已影响0人  CesarMing

R语言中使用subset()和while取子集,你会发现子集的因子水平数没有改变。
那么问题来了,对子集用table()怎么才能去掉未使用的因子?

droplevels()可以将未使用的因子水平从一个因子或者一个数据框中去掉。
The function droplevels is used to drop unused levels from a factor or, more commonly, from factors in a data frame.

在R中演示代码如下:

subset().jpg
上一篇 下一篇

猜你喜欢

热点阅读