Re: [R] Changing selected elements of an array

2012-05-21 Thread Øystein Godøy
Joshua Wiley wrote on 2012-05-21 ... > > This looks interesting and is what I want, but I am not fully > > understanding the output I receive. The input array has 100 elements > > while the resulting vector after replacement is 106 elements long. I > > have tried to understand the manual on this, b

Re: [R] Changing selected elements of an array

2012-05-21 Thread Joshua Wiley
On Mon, May 21, 2012 at 9:27 AM, Øystein Godøy wrote: > Hi Joshua, > > Many thanks for your quick reply. > >> 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

Re: [R] Changing selected elements of an array

2012-05-21 Thread Øystein Godøy
Hi Joshua, Many thanks for your quick reply. > 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"))] <-

Re: [R] Changing selected elements of an array

2012-05-21 Thread Joshua Wiley
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()