rtapply

R Studio getting the mean of vector of first 5 values, next 5 values etc


The code I am using is tapply(g,?, mean), the tapply function but I am confused about what to put in between g which is my vector, and the mean. The question asks to get the mean of each set of 5 values in a vector of size 100. So I will have 20 means altogether. Any help is appreciated!


Solution

  • g<-c(1:100)
    y<-rep(1:20, each=5)
    tapply(g, y, mean)