Average Of Rows In Rstudio Reduce Count

[Solved] Average Of Rows In Rstudio Reduce Count | Perl - Code Explorer | yomemimo.com
Question : average of rows in Rstudio reduce count

Answered by : arich

df <- data.frame(a=1:12, b=13:24 );
df;
## a b
## 1 1 13
## 2 2 14
## 3 3 15
## 4 4 16
## 5 5 17
## 6 6 18
## 7 7 19
## 8 8 20
## 9 9 21
## 10 10 22
## 11 11 23
## 12 12 24
n <- 5;
aggregate(df, list(rep(1:(nrow(df) %/% n + 1), each = n, len = nrow(df))), mean)[-1];
## a b
## 1 3.0 15.0
## 2 8.0 20.0
## 3 11.5 23.5

Source : https://stackoverflow.com/questions/30359427/calculate-the-mean-of-every-13-rows-in-data-frame | Last Update : Thu, 11 Nov 21

Answers related to average of rows in rstudio reduce count

Code Explorer Popular Question For Perl