Re: [R] calculate multiple means of one vector

2011-10-10 Thread Dennis Murphy
Hi: Here's one approach: dat <- rnorm(40, 0, 2) positions <- matrix(c(3, 4, 5, 8, 9, 10, 20, 21, 22, 30, 31, 32), ncol = 3, byrow = TRUE) # Subdata t(apply(positions, 1, function(x) dat[x])) [,1] [,2] [,3] [1,] 0.5679765 1.429396 2.9050931 [2

[R] calculate multiple means of one vector

2011-10-10 Thread Martin Batholdy
Dear R-Users, I have the following two vectors: data <- rnorm(40, 0, 2) positions <- c(3, 4, 5, 8, 9, 10, 20, 21, 22, 30, 31, 32) now I would like to calculate the mean of every chunk of data-points (of the data-vector) as defined by the positions-vector. So I would li