是否有一种简单的方法来重新编码因子变量的水平,使得低于给定频率出现的水平被重新编码为“其他”变量?
theshold <- c(0.001, 0.5, 0.1)
df$a df$b df$c - 基于小于第一个阈值的级别频率重新编码级别
df$x df$y df$x - 基于小于第一个阈值的级别频率重新编码级别小于第二阈值
df$d df$e df$f - 根据小于第三阈值的级别频率重新编码级别
theshold <- c(0.001, 0.5, 0.1)
df$a df$b df$c - Recode levels based on level frequency of less than first threshold
df$x df$y df$x - Recode levels based on level frequency of less than second threshold
df$d df$e df$f - Recode levels based on level frequency of less than third threshold
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找
fct_lump_prop()
来自forcats
。输出
由
You're looking for
fct_lump_prop()
fromforcats
.Output
Created on 2022-03-31 by the reprex package (v2.0.0)
可能会有一个更容易的
整洁
这样做的方法,但是您可以编写一个可以实现此功能的功能:在2022-03-31上由 reprex软件包(v2.0.1)
There may be an easier
tidy
way of doing this, but you could write a little function that would implement this:Created on 2022-03-31 by the reprex package (v2.0.1)
有了Andreas的建议和进一步的阅读,我想出了以下内容,这可以享受待遇。谢谢
with Andreas suggestion and further reading, i came up with the following which worked a treat. thanks