[R-sig-Geo] exporting weiths matrix in .txt-file in spdep

Roger Bivand Roger.Bivand at nhh.no
Tue Mar 22 21:16:36 CET 2005


On Tue, 22 Mar 2005, Mario Gellrich wrote:

> Hi,
> 
> I have created a row-standardized spatial weigths matrix in spdep and 
> wonder how it can be transformed to a simple .txt-file for export to other 
> programs or simply visualisation of the weights matrix in form of rows and 
> columns. Does anybody have a clue how to write out a weights matrix in spdep?

For example:

> library(spdep)
> data(columbus)
> colnbMat <- nb2mat(col.gal.nb, style="B")
> str(colnbMat)
 num [1:49, 1:49] 0 1 1 0 0 0 0 0 0 0 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:49] "1005" "1001" "1006" "1002" ...
  ..$ : NULL
 - attr(*, "call")= language nb2mat(neighbours = col.gal.nb, style = "B")
> library(MASS)
> mattmp <- tempfile()
> write.matrix(colnbMat, file=mattmp)
> system(paste("cat", mattmp))
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
....

For visualisation, this is nice, and scales to largish n:

> image(asMatrixCsrListw(nb2listw(col.gal.nb, style="B")))

Roger


> 
> Best regards
> 
> Mario Gellrich
> --------------------------------------------------
> Mario Gellrich
> Swiss Federal Research Institute WSL
> Economics Section
> Zürcherstrasse 111
> CH-8903 Birmensdorf
> Tel:       ++41 (0)1 739 2520
> Fax:       ++41 (0)1 739 22 15
> e-mail:    mario.gellrich at wsl.ch
> Web: http://www.wsl.ch/phonebook/STAFF/2409.ehtml
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list