[R] expression with running index
Uwe Ligges
ligges at statistik.uni-dortmund.de
Sun Apr 25 20:34:31 CEST 2004
Tamas Papp wrote:
> Hi,
>
> 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[0]), expression(b[1]), expression(b[2]))
>
> "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.
>
> Thanks,
>
> Tamas
>
For example:
lapply(as.double(-1:2), function(x) substitute(b[i], i = list(i=x)))
Uwe Ligges
More information about the R-help
mailing list