[R] Neighbour List to Matrix

ilai keren at math.montana.edu
Fri Feb 17 23:25:33 CET 2012


 I think is good to know that list contain more than 600000 rows with
around 14000 nodes (participants).

?read.table may be unreliable for large matrices and with 14/600
you'll end up with many NA's. You might do better with

nbrs<- scan('nbrs.txt',skip=1,what=list('integer','integer',double(0)))
names(nbrs) <- c('c1','c2','c3')
xtabs(c3~c1+c2,nbrs,sparse=T)

# returns
4 x 9 sparse Matrix of class "dgCMatrix"
      1     2     3     4     5     6     7     8     9
1 .     0.065 0.044 .     .     .     .     .     .
3 0.071 .     .     0.016 0.011 .     .     .     .
4 .     .     0.004 .     .     .     0.004 .     0.004
5 .     .     .     0.010 .     0.011 .     0.009 0.004

Cheers



More information about the R-help mailing list