I have a georeferenced event data set, in a data frame of the form:
LONGITUDE LATITUDE VAR1
33.4 4.4 5
33.4 4.4 3
33.4 4.4 1
30.4 4.2 2
28.4 5.1 2
It counts fatalities in events which are georeferenced. Apart from it, I have a shape file of the provinces in a country, like this:
> str(shapefile)
'data.frame': 216 obs. of 5 variables:
$ CONSTI_COD: num 1 2 3 4 5 6 7 8 9 10 ...
$ Area : num 20 11.7 10.7 223.3 38.7 ...
$ PROVINCE_NAME : Factor w/ 216 levels "CENTRAL","COAST",..: 4 4 4 4 4 4 4 4 2 2 ...
$ Shape_Leng: num 0.193 0.152 0.201 0.872 0.441 ...
$ Shape_Area: num 0.001628 0.000947 0.000867 0.018135 0.003145 ...
..@ polygons :List of 216
.. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
.. .. .. ..@ Polygons :List of 1
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 36.9 -1.3
.. .. .. .. .. .. ..@ area : num 0.00163
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:151, 1:2] 36.8 36.8 36.8 36.9 36.9 ...
.. .. .. ..@ plotOrder: int 1
.. .. .. ..@ labpt : num [1:2] 36.9 -1.3
.. .. .. ..@ ID : chr "0"
.. .. .. ..@ area : num 0.00163
[...etc]
What I need to do is to place the event data within the provinces, i.e. add a fourth column to the first data frame which states in which province happened each event, based on the coordinates. So I would have something like this:
LONGITUDE LATITUDE VAR1 PROVINCE
33.4 4.4 5 CENTRAL
33.4 4.4 3 CENTRAL
33.4 4.4 1 CENTRAL
30.4 4.2 2 COAST
28.4 5.1 2 COAST
Is this posible? I think I found some time ago a post that explained how to do this (outside Stack Overflow), but I cannot find it now.
Thanks!
(Sorry if there is a similar question over here. I made a search, but I didn't find an answer, maybe because I don't really know what I'm looking for. I would really appreciate a link to a similar post.)