I think this may help.

my_assign <- function(operand, value) {
  assignment <- paste(operand, value, sep = "<-")
  e <- parse(text = assignment)
  eval.parent(e)
}

a <- rep(0,5)
> a
[1] 0 0 0 0 0

my_assign("a[2]", 7)

> a
[1] 0 7 0 0 0

my_assign("a[4]", 12)

> a
[1] 0 7 0 12 0


--
GG

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to