On 24 Apr 2014, at 23:56, Greg Snow <[email protected]> wrote:

> library(Matrix)
> 
> adjM <- Matrix(0,nrow=10,ncol=10)
> 
> locs <- cbind( sample(1:10), sample(1:10) )
> vals <- rnorm(10)
> 
> adjM[ locs ] <- vals

... and once you've got your data in this format, why not construct the sparse 
matrix directly?

        adjM <- sparseMatrix(i = locs[,1], j = locs[,2], x = vals)

I've found this to be very efficient and have used it with sparse matrices 
containing up to around 100 million nonzero entries.

Hope this helps,
Stefan
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to