Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_distance

Distance in kilometers or miles between two locations based on lat-long Function based on http://www.movable-type.co.uk/scripts/latlong.html. Uses the haversine formula


Description

Distance in kilometers or miles between two locations based on lat-long Function based on http://www.movable-type.co.uk/scripts/latlong.html. Uses the haversine formula

Usage

as_distance(
  lat1,
  long1,
  lat2,
  long2,
  unit = "km",
  R = c(km = 6371, miles = 3959)[[unit]]
)

Arguments

lat1

Latitude of location 1

long1

Longitude of location 1

lat2

Latitude of location 2

long2

Longitude of location 2

unit

Measure kilometers ("km", default) or miles ("miles")

R

Radius of the earth

Value

Distance between two points

Examples

as_distance(32.8245525,-117.0951632, 40.7033127,-73.979681, unit = "km")
as_distance(32.8245525,-117.0951632, 40.7033127,-73.979681, unit = "miles")

radiant.data

Data Menu for Radiant: Business Analytics using R and Shiny

v1.3.12
AGPL-3 | file LICENSE
Authors
Vincent Nijs [aut, cre]
Initial release
2020-11-25

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.