I'm practicing dplyr package, and I have some problem when calculating mean by group. Here's a subset of my data
head(Data)
CodeProject Price
Pr1 3
Pr1 4
Pr1 5
Pr2 6
Pr2 9
I would like to calculate mean for each project, I tried the following code
library(dplyr)
Data %>%
group_by(Data$CodeProject) %>%
summarize(
n = n(),
mean_pr = mean(Price, na.rm=T)
)
But when I do that, I get this result :
Data$CodeProject n mean_pr
Pr1 3 5.4
Pr2 2 5.4
I tried to add dplyr::summarize, but same result
How can I fix that ?
Thank you very much