我有一个快速的问题。为什么这段代码给我们所有数据的平均值,而不是X内的平均值?
df1 <- data.frame(X = rep(x = LETTERS[1:2], each = 3), Y = 1:6)
df1<-df1%>%group_by(X)%>%mutate(meanY=mean(Y))
我有一个快速的问题。为什么这段代码给我们所有数据的平均值,而不是X内的平均值?
df1 <- data.frame(X = rep(x = LETTERS[1:2], each = 3), Y = 1:6)
df1<-df1%>%group_by(X)%>%mutate(meanY=mean(Y))
The reason is that
mutate
loaded is fromplyr
masking thedplyr::mutate
. Either do this on a freshR
session without loading theplyr
or use::
to specify the package nameOP's case can be replicated if we use
plyr::mutate