Error in mutate_impl(.data, dots) :
Column `month` can't be modified because it's a grouping variable
我想用其中一个轴作为一年中的一个月,但我希望从8月到7月。我也想"周"显示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
,因为它是一个分组变量
答案 0 :(得分:1)
我遇到了同样的问题,并使用ungroup()解决了这个问题:
df <- df %>%
ungroup(var) %>%
mutate(var = factor(var,levels = c(1,2,3),
labels = c("label1","label2","label3") ) )