Skip to content
Prev 6959 / 63468 Next

Feature Request: "matrix[1:10,1:10, block=F] <- 1:10"

Gregory R Warnes <gregory_r_warnes@groton.pfizer.com> wrote:
R> m <- matrix("", nrow=3,ncol=3)
 R> index_i <- c(2,1,3)
 R> index_j <- c(1,3,2)
 R> vals    <- c("a","b","c")
 R> m[ index_i, index_j ] <- vals

but what he wants to get is:
 >      [,1] [,2] [,3]
 > [1,]   ""   ""  "b"
 > [2,]  "a"   ""   ""
 > [3,]   ""  "c"   ""

Just do this instead:
 R> m[ cbind(index_i, index_j) ] <- vals