I have two spatial points dataset, one for origins and one for destinations.
I'd like to take the most recurring trajectories from these coordinates.
> salidas
class : SpatialPointsDataFrame
features : 4385
extent : -8.694846, -8.339238, 41.00827, 41.25749 (xmin, xmax, ymin, ymax)
crs : +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
variables : 3
names : cod, duracion, franja_h
min values : 1.37263685362e+18, 315, 1
max values : 1.37274729362e+18, 13830, 96
> llegadas
class : SpatialPointsDataFrame
features : 4385
extent : -8.756604, -7.739523, 40.48858, 41.4262 (xmin, xmax, ymin, ymax)
crs : +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
variables : 3
names : cod, duracion, franja_h
min values : 1.37263685362e+18, 315, 1
max values : 1.37274729362e+18, 13830, 96
I think the points should be kept discreet, as they are not too specific and do not give too much information, so I've made a grid of X and Y coordinates for it.
> GridSalidas
X Y Count
1 -8.3375 41.1975 1
2 -8.5125 41.2025 1
3 -8.5325 41.1425 1
4 -8.5325 41.2075 1
5 -8.5325 41.2225 1
6 -8.5475 41.2025 1
7 -8.5475 41.2075 1
8 -8.5475 41.2325 1
9 -8.5525 41.2075 1
10 -8.5525 41.2175 1
> GridLlegadas
X Y Count
1 -7.7375 41.2975 1
2 -7.8625 40.4875 1
3 -8.1475 41.1875 1
4 -8.3075 41.1975 1
5 -8.4725 41.3225 1
6 -8.4875 41.1875 1
7 -8.4925 41.1925 1
8 -8.4975 41.1875 2
9 -8.5025 41.0425 1
10 -8.5025 41.1925 1
As a result, I'd like to find out which trajectories are more common depending on the origin and the destination.
Thanks!
All you are asking for is some multi-dimensional binning.
I generated a random dataset
dt
of origin and destination for the purpose of demonstration. The output result is adata.table
that gives the following information about the most frequent trajectory: