Hi,
I have a simple df I would like to summarise (IntYear in the first column, IntMonth in the next, mean scores of four measures and count in the end).
I have an error and I don't know what is wrong.
Can you help please?
data.source <- data.frame(stringsAsFactors=FALSE,
DF.URN = c("C688230", "C688234", "C888832", "C889311", "C889312",
"C889313", "C889320", "C889353", "C889359",
"C989839", "V08152703", "V09159381",
"V11187611", "V11187616", "V12196198", "V12196205",
"V12196208", "CE90195359", "CE90195377",
"CE90195408", "CE90195411", "CE90195413", "CE90195450",
"CE90195455"),
Sat_Score = c(90, 100, 90, 80, 100, 100, 100, 90, 90, 100, 80, 70, 90,
100, 90, 100, 50, 100, 100, 90, 100, 70, 100,
100),
Rec_Score = c(90, 100, 90, 70, 100, 100, 100, 90, 90, 100, 80, 90, 90,
100, 80, 100, 40, 100, 100, 90, 100, 100,
100, 100),
Staff_Score = c(90, 100, 80, 90, 100, 90, 100, 90, 90, 100, 80, 90, 90, 100,
50, 100, 60, 100, 100, 100, 100, 60, 100,
100),
Value_Score = c(90, 100, 80, 60, 100, 90, 100, 90, 80, 100, 60, 70, 90, 100,
100, 90, 80, 100, 100, 90, 100, 90, 100,
100),
IntDate = c("2017-07-03", "2017-07-04", "2017-08-07", "2017-09-04",
"2017-08-29", "2017-09-01", "2017-08-29",
"2017-09-07", "2017-09-01", "2017-10-02",
"2018-10-12", "2018-10-03", "2018-11-30", "2018-11-30",
"2018-12-31", "2018-12-31", "2018-12-31",
"2019-01-21", "2019-01-23", "2019-02-04",
"2019-01-29", "2019-01-31", "2019-02-04", "2019-02-04"),
IntYear = c(2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017,
2018, 2018, 2018, 2018, 2018, 2018, 2018,
2019, 2019, 2019, 2019, 2019, 2019, 2019),
IntMonth = c(7, 7, 8, 9, 8, 9, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12,
1, 1, 2, 1, 1, 2, 2)
)
library(dplyr)
Y.M <- data.source %>%
group_by(IntYear,IntMonth) %>%
summarise(Rec_Score = mean(Rec_Score),
Sat_Score = mean(Sat_Score, na.rm = TRUE),
Staff_Score = mean(Staff_Score, na.rm = TRUE)) %>%
mutate(Rec_Score = n())
Y.M
error:
Error: n() should only be called in a data context