2
I have this data set:
mes <- c("jan","fev","jan","abr","fev","abr","jan","fev","abr")
a <- c(32.3,32.7,32.6,33.1,33.0,33.5,33.4,33.4,34.9)
b <- c(19.2,19.2,19.6,19.7,19.7,19.9,20.0,20.0,20.4)
c <- c(14.7,15.0,15.6,16.2,16.4,17.0,17.7,18.3,19.1)
d <- c(24.2,24.3,24.7,25.0,25.5,26.4,26.7,27.1,27.6)
temp <- data.frame(mes,a,b,c,d)
I am grouping as follows, using the package dplyr
base <- temp %>%
group_by(mes) %>%
summarise(n = length(mes), med.a = mean(a),
med.b=mean(b),med.c=mean(c),med.d=mean(d))
I’d like to group by the column mes of data.frame counting the number of observations and also calculating the averages for all columns at once, without having to name each new column that will be calculated the average.
has how to do this procedure? I would like to write in a way that I could use other data.frame with different column numbers without always having to name them. For the process to be automatic and run in other databases I have.