Skip to content
Prev 321402 / 398500 Next

how to calculate average of each column

Hello,

You should provide us with a data example, like the posting guide asks 
you to.
Without one, you could adapt the following example to your case


# Make up some data
dat <- data.frame(X = rnorm(200), Y = rnorm(200))

# Divide into subsets of 60 rows each and compute the col means
grp <- rep(1:(1 + nrow(dat) / 60), each = 60)[seq_len(nrow(dat))]
do.call(rbind, lapply(split(dat, grp), colMeans))


Hope this helps,

Rui Barradas

Em 10-04-2013 18:46, Ye Lin escreveu: