within_km: Identify rows of dataframe with observations in certain...

View source: R/misc.R

within_kmR Documentation

Identify rows of dataframe with observations in certain distance from point

Description

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.

Usage

within_km(df, start_longitude, start_latitude, km)

Arguments

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

Details

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.

Value

Logical vector indicating which rows of df are within km from starting point @export


LukasWallrich/rNuggets documentation built on Aug. 26, 2022, 11:03 a.m.