编辑:我的问题不够清楚。我道歉。
问题是定义组并将数据框列的值分配给它。我用 ifelse 链和这里的评论自己解决了这个问题。感谢那。然后我分别为每一列手动完成。
data %>%
mutate(group = ifelse(richness <= -0.6, "1",
ifelse(richness > -0.6 & richness <= -0.2, "2",
ifelse(richness >-0.2 & richness <= 0.2, "3",
ifelse(richness >0.2 & richness <= 0.6, "4",
ifelse(richness >0.6, "5", NA)))))) %>%
group_by(group) %>%
summarise(percentage=n()*100/"No.of.values")