[R] applying a function in list of indexed elements of a vector:
aldi
aldi at dsgmail.wustl.edu
Sat Mar 10 23:01:06 CET 2012
Hi,
I have a vector
Y1 <-c(8, 11, 7, 5, 6, 3, 6, 3, 3)
and an index
iy <-c(c(1, 2),c(1 2), c(1, 2, 3, 4), c(2, 3, 5), c(4), c(5, 6, 7), c(7,
8, 9))
how can I produce the mean, or the sum of the elements specified in the
index iy from the vector Y1?
expecting something like this for the sum:
Y2
19 19 31 24 5 15 12
I thought lapply function may perform this, but does not work:
Y2<-lapply(Y1[iy],sum)
Any suggestion?
TIA,
Aldi
--
More information about the R-help
mailing list