【发布时间】:2020-10-08 16:34:23
【问题描述】:
我有一个包含因子的数据框。对于因子水平之一(etoh2),我想计算“从不”一词的出现次数,然后将其除以总数(不包括 na)来计算。百分比。
df 的结构如下所示: structure of df
并且 etoh2 的级别看起来像这样(使用 sapply):etoh levels
现在,我尝试使用 dplyr 进行过滤:
vipcls$etoh2 %>%
never <- count(filter(etoh2 == "never")
all <- count(etoh2)
ratio <- never/all
这给了我以下错误消息:error message
非常感谢任何帮助!
【问题讨论】: