within_km | R Documentation |
within_km
tests for each line of a dataframe with longitude and
latitude variables whether the location so described is within a certain
radius from a given starting point.
within_km(df, start_longitude, start_latitude, km)
df |
Dataframe with observations, must include latitude and longitude variables in degrees |
start_longitude |
Longitude of starting point in degrees. |
start_latitude |
Latitude of starting point in degrees. |
km |
Distance from starting point to filter line by |
Note that this function is very inefficient. It calculates the distance of each line to the starting point using the Haversine formula. If you need to use this regularly or on large datasets, a previous step to throw out lines that are clearly too far away based on either latitude or longitude would greatly increase efficiency.
Logical vector indicating which rows of df
are within
km
from starting point
@export
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.