Error in mutate_impl(.data, dots) :
Column `month` can't be modified because it's a grouping variable
我想绘制一个轴是一年中的月份,但是我希望它从八月到七月。我还希望“周”显示 1-5 而不是 5-1.....但是当我尝试以下代码时它不允许我这样做:
Admit_Weekly1 <- Admit_Weekly %>%
+ filter(Retention_Status == 1) %>%
+ mutate(week = factor(week,levels(week)[1,2,3,4,5])) %>%
+ mutate(month = factor(month,levels(month)["August","September","October","November",
+ "December","January","February","March",
+ "April", "May","June","July"]))
mutate_impl(.data, dots) 中的错误:
week
列无法修改,因为它是一个分组变量 最佳答案
我遇到了同样的问题并使用 ungroup() 解决了它:
df <- df %>%
ungroup(var) %>%
mutate(var = factor(var,levels = c(1,2,3),
labels = c("label1","label2","label3") ) )
关于r - 使用 mutate() 返回关于无法修改的错误,因为它是一个分组变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50029128/