[R] building a spatial matrix
A M Lavezzi
mario.lavezzi at unipa.it
Thu May 12 11:26:23 CEST 2016
Hello,
I have a sample of 1327 locations, each one idetified by an id and a
numerical code.
I need to build a spatial matrix, say, M, i.e. a 1327x1327 matrix
collecting distances among the locations.
M(i,i) should be 0, M(i,j) should contain the distance among location i and
j
I shoud use data organized in the following way:
1) id_cell contains the identifier (id) of each location (1...1327) and the
numerical code of the location (f_cell) (see head of id_cell below)
> head(id_cell)
id f_cell
1 1 2120
12 2 204
22 3 2546
24 4 1327
34 5 1729
43 6 2293
2) censDist contains, for each location identified by its numerical code,
the distance to other locations (censDist has 1.5 million rows). The
head(consist) below, for example, reads like this:
location 2924 has a distance to 2732 of 1309.7525
location 2924 has a distance to 2875 of 696.2891,
etc.
> head(censDist)
f_cell f _cell_neigh distance
1 2924 2732 1309.7525
2 2924 2875 696.2891
3 2924 2351 1346.0561
4 2924 2350 1296.9804
5 2924 2725 1278.1877
6 2924 2721 1346.9126
Basically, for every location in id_cell I should pick up the distance to
other locations in id_cell from censDist, and allocate it in M
I have not come up with a satisfactory vectorizion of this problem and
using a loop is out of question.
Thanks for your help
Mario
--
Andrea Mario Lavezzi
DiGi,Sezione Diritto e Società
Università di Palermo
Piazza Bologni 8
90134 Palermo, Italy
tel. ++39 091 23892208
fax ++39 091 6111268
skype: lavezzimario
email: mario.lavezzi (at) unipa.it
web: http://www.unipa.it/~mario.lavezzi
[[alternative HTML version deleted]]
More information about the R-help
mailing list