[R] Matching
shish matt
shishm at yahoo.com
Sat Oct 29 00:22:49 CEST 2011
I have a spatial weight file in csv that I want as listw object in R.
The file has the following 3 variables (left to right in the file) -- OID_, NID and WEIGHTS. NID stands for the neighbors and OID_ as the origins. There are 217 origins with 4 neighbors each.
I have been able to read the csv file as a data frame (test.csv). Then I tried to check whether the OID_ variable is in the right place in the dataframe. I used "match" for that using:
o
<- match(OID_, OID_)
I am not sure whether this is the right way to match. Please advice.
Anyway, next I created a matrix object (m) using:
m
<- as.matrix(test.csv[, -1])
Then I created object m1, using:
m1
<- m[o, o]
Finally, I tried creating listw object using:
mat2listw(m1)
Here I get an error that x is not a square matrix.
Not sure what to do now. Any helo appreciated!
Thanks,
Shishm
More information about the R-help
mailing list