[R] assigning values to elements of matrixes

Giorgio Garziano giorgio.garziano at ericsson.com
Wed Dec 23 15:13:34 CET 2015


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]]



More information about the R-help mailing list