熊猫新手,我想执行类似于Reduce number of levels for large categorical variables(分类变量的组合,以降低它们的级别) 下面的代码在R中可以正常工作
DTsetlvls <- function(x, newl)
setattr(x, "levels", c(setdiff(levels(x), newl), rep("other", length(newl))))
我的数据帧:
^{pr2}$我手动创建一个聚合列,然后基于此,将频率较低的组(如“blue”标记为单个“other”组)。 但与简洁的R代码相比,这似乎有些笨拙。在这里正确的方法是什么?在
我认为您可以将^{} 与^{} 一起使用,其中条件与^{} 一起使用:
^{pr2}$
或者,如果需要替换所有非top值,请使用^{} :
相关问题 更多 >
编程相关推荐