From brahm@alum.mit.edu  Wed Feb 20 22:20:45 2002
From: brahm@alum.mit.edu (David Brahm)
Date: Wed, 20 Feb 2002 17:20:45 -0500
Subject: [Rd] Feature Request: "matrix[1:10,1:10, block=F] <- 1:10"
In-Reply-To: <5429125E11E4D411AF7300805FE603A8040DE6C6@groexmbcr02.pfizer.com>
References: <5429125E11E4D411AF7300805FE603A8040DE6C6@groexmbcr02.pfizer.com>
Message-ID: <15476.8509.861348.611923@gargle.gargle.HOWL>

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

-- 
                              -- David Brahm (brahm@alum.mit.edu)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


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