Please folks!
Why issue protestations of "clumsiness" when all you have to do is
make some effort to learn R?
See section 5.3 of an Intro to R -- which ships with every copy of R
-- on matrix indexing.
?"["
also documents the behavior, albeit more tersely. ("... a third form
of indexig ...")
On 19-03-2012, at 22:07, David Stevens wrote:
> I'm a bit clumsy about many things in R. Here's my problem. I'm trying to
> build a square sparse matrix and populate it without looping (bad practice,
> right). I have vectors of matched row/column pairs for which the matrix
> entries have commo
I suspect I'm misinterpreting what you are trying to do, because it
seems unlikely that the solution is as simple as:
A <- matrix(0, 20, 20)
iRows <- c(2,3,4,6,7,8,10,11,12,14,15,16,18,19)
iCols <- c(1,2,3,5,6,7,9,10,11,13,14,15,17,18)
A[iRows, iCols] <- 1 # or a vector of the same length in the s
http://cran.r-project.org/doc/manuals/R-lang.html#Indexing-matrices-and-arrays
matrix[cbind(iRows, iCols)] <- values
Peter
On Mon, Mar 19, 2012 at 2:07 PM, David Stevens wrote:
> I'm a bit clumsy about many things in R. Here's my problem. I'm trying to
> build a square sparse matrix and populat
On Mon, Mar 19, 2012 at 2:07 PM, David Stevens wrote:
> I'm a bit clumsy about many things in R. Here's my problem. I'm trying to
> build a square sparse matrix and populate it without looping (bad practice,
> right). I have vectors of matched row/column pairs for which the matrix
> entries have c
I'm a bit clumsy about many things in R. Here's my problem. I'm trying
to build a square sparse matrix and populate it without looping (bad
practice, right). I have vectors of matched row/column pairs for which
the matrix entries have common characteristics and am look for a way to
fill the ent
6 matches
Mail list logo