[R] expression with running index
ligges at statistik.uni-dortmund.de
Sun Apr 25 20:34:31 CEST 2004
Tamas Papp wrote:
> I need a list of expression of the form expression(b[i]), where i is a
> running index. So for example, if i <- -1:2, I would like to have a
> list equivalent to
> list(expression(b[-1]), expression(b), expression(b), expression(b))
> "i" might be a character vector (like c("f", "g", "h"))
> Could somebody help me out by writing a function that produces the
> list above for a given string in place of "b" and a vector of subscripts?
> Sorry if this has been discussed before, I tried searching the
> archives but "expression" as a keyword gives too many results on
> different subjects.
lapply(as.double(-1:2), function(x) substitute(b[i], i = list(i=x)))
More information about the R-help