When I try to calculate a distance matrix and a corresponding weights matrix with the spacom package in R, I encounter the following problem (find here a replicable example):
> distmatrix <- DistanceMatrix(mafialomb, "NOME_COM", longlat = FALSE)
> weights <- WeightMatrix(distmatrix, 5000000)
> is.numeric(distmatrix)
TRUE
> is.numeric(weights)
FALSE
In order to proceed with the estimation, I need the weights matrix to be numeric. R Studio tells me that the distmatrix is data, while weights is a "Formal class dsCMatrix" and falls under "Values". When I call:
> head(weights)
I get the following description:
6 x 8 sparse Matrix of class "dgCMatrix"
Do you know of:
- any way to make this matrix numeric; or
- any other method to calculate spatial weights that would output a numeric weights matrix?
This should work: