[R] Filling matrices

2012-03-19 Thread David Stevens
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

Re: [R] Filling matrices

2012-03-19 Thread Peter Langfelder
On Mon, Mar 19, 2012 at 2:07 PM, David Stevens david.stev...@usu.edu 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

Re: [R] Filling matrices

2012-03-19 Thread Peter Meilstrup
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 david.stev...@usu.eduwrote: I'm a bit clumsy about many things in R. Here's my problem. I'm trying to build a square sparse

Re: [R] Filling matrices

2012-03-19 Thread Sarah Goslee
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 same

Re: [R] Filling matrices

2012-03-19 Thread Berend Hasselman
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 common

Re: [R] Filling matrices

2012-03-19 Thread Bert Gunter
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 ...) (ergo