[R] lapply-related question
Ott Toomet
siim at localhost.localdomain
Mon Sep 9 18:04:14 CEST 2002
Dear R-gurus,
I would like to use a lapply on a kind of "bivariate" problem. I have
a vector and a list, components of which are vectors, e.g.
vec <- c(1,2,3)
lst <- list(1, c(2,3), c(4,5,6))
I want to apply a function to each component of the list, using the
corresponding component of the vector as a parameter. E.g. I want a
list in the form
list(lst[[1]] + vec[1], lst[[2]] + vec[2], .... )
I think this can be achieved with a cycle and probably using lapply
with a function, storing the index in an outer environment as
i <- 1
lapply(lst, FUN=function(x) {x + vec[i]; i <<- i + 1})
but are there any more cleaner solution?
Best regards,
Ott
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list