I have a data.table that holds ids and locations. for example, here is it with one row in it: (it has col and row names, don\'t know if it matters)
locations<-
No loops are required, just use data.table
as intended. If all you want to see are the rows that within 50 meters from the desired location, all you have to do is
locations[, if (gdist(-159.58, 21.901, location_lon, location_lat, units="m") <= 50) .SD, id]
## id location_lon location_lat
## 1: 11 -159.58 21.901
Here we are iterating by the id
column within the locations
data set itself and checking if each id
is within 50 meters from -159.58, 21.901
. If so, we are calling .SD
which is basically the data set itself for that specific id
.
As a side note, data.table
doesn't have row.names
, so there is no need of specifiying them, see here, for example