Skip to content
Prev 295183 / 398506 Next

Changing selected elements of an array

Hi ?ystein,

You can do it by passing a matrix for indexing instead of two vectors.
 Here's an example:


tmpmat <- matrix(NA, nrow = 10, ncol = 10,
  dimnames = list(letters[1:10], LETTERS[1:10]))

tmpmat[cbind(c("d", "e", "f"), c("D", "E", "F"))] <- 100
tmpmat

The matrix is created using cbind() to columnwise bind the two vectors
together.  Then it does what you want I think.

Hope this helps,

Josh
On Mon, May 21, 2012 at 7:15 AM, ?ystein God?y <o.godoy at met.no> wrote: