[R] Matching
Joshua Wiley
jwiley.psych at gmail.com
Sun Oct 30 01:49:42 CEST 2011
Hi Shishm,
Part of what you do seems reasonable. My guess is that:
o <- match(OID_, OID_)
is not doing what you want/think. What happens when you look at the
results? e.g.,:
print(o)
You use that later on as row and column indices to extract from m, to
create m1. The fact taht mat2listw complains that m1 is not square,
makes me guess the indices used to create m1 are not working
correctly, which points back to o <- match().
With a more detailed example we can give more detailed suggestions
Hope this helps some,
Josh
On Fri, Oct 28, 2011 at 3:22 PM, shish matt <shishm at yahoo.com> wrote:
> 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
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/
More information about the R-help
mailing list