Thank you very much for your help, Nikhil! The code I'm using now is
#generate data
set.seed(2)
x <- as.matrix(runif(5))
id1 <- sample(1:2,5,replace=T)
id2 <- c(1:5)
rownames(x) <- paste(id1, id2)
#create distance matrix if same id1
x.L <- split(x,id1)
n.L <- split(rownames(x), id1)
for(i in 1:le
My mistake, instead of colnames(d1)
use substr(colnames(d1),1,1) or similar
On Jul 19, 2010, at 2:15 PM, Nikhil Kaza wrote:
Michael,
You can modify the following code to suit. Also avoid using dist as
a variable name since it is a function in base. However, are you
sure you want to do thi
Michael,
You can modify the following code to suit. Also avoid using dist as a
variable name since it is a function in base. However, are you sure
you want to do this? Sx is the variance using sites in all the regions!
d1 <- apply(x,1, function(i){mahalanobis(x,i,Sx)})
is.na(d1) <- !sapply(
Thanks for the tip, Nikhil. However, i need only one matrix as input
for another to compute for non-bipartite matching which minimizes
pairwise distances between observations. As such, I need the
georeference (id) of the observations for subsequent processing. Below
is an illustration.
> #generat
Thanks for the tip, Nikhil. However, i need only one matrix as input for
another to compute for non-bipartite matching which minimizes pairwise
distances between observations. As such, I need the georeference (id) of the
observations for subsequent processing. Below is an illustration.
> #generate
replace dist with mahalanobis distance in the following example.
a <- cbind(runif(10), sample(1:3, 10, replace=T))
a.L <- split(a,a[,2])
dist.L <- lapply(a.L, dist)
Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina
nikhil.l...@gmail.com
On Jul 19, 2010, at
Hi! I am trying to implement non-bipartite matching. I have around 500 sites
which can be clustered by 10 regions. I am able to calculate pairwise
Mahalanobis distances between sites (thanks to another post in the forum).
However, I want to constrain my match to sites within the same region. Thus
I
7 matches
Mail list logo