gc_endpoints: Generate a table of location pair samples

Description Usage Arguments Details Value Examples

View source: R/networks.R

Description

Expand a table of location samples to location pairs.

Usage

1
gc_endpoints(data, lon, lat, distance = TRUE, keep = TRUE)

Arguments

data

a data frame.

lon

character, the column in data referring to longitudes.

lat

character, the column in data referring to latitudes.

distance

logical, include a column of distances between locations along the shorter arc of the implied great circle. Defaults to TRUE.

keep

logical, retain copies of other columns in data if data contained more than longitude and latitude columns. Defaults to TRUE.

Details

gc_endpoints expands a data frame of with longitude and latitude coordinate columns into one with four columns of lon0, lat0, lon1 and lat1 representing pairs of locations. This is done in preparation for generating great circle arcs between each pair of locations. gc_endpoints provides the endpoints of these arcs. See gc_lines, which is used subsequently on output from gc_endpoints, to generate an expanded data frame of the corresponding great circle ars.

gc_endpoints merely splits a data frame into its first and second halves of rows and then expands a table that has rows for every combination of pairs between the first and second halves of the original table. This is a handy utility function for preparing data for simulated examples of network maps in the current version of mapmate. In future versions a more robust gc_endpoints may offer other more controllable options for assembling location pairs.

When keep=TRUE columns in data other than those of longitudes and latitudes are similarly appended with 0 and 1 in the output, corresponding to the columns lon0/lat0 and to lon1/lat1, respectively.

If data contains n rows, then the data frame returned by gc_endpoints will contain (n/2)^2 rows.

Value

a data frame.

Examples

1
2
3
4
5
6
## Not run: library(dplyr)
data(network)
gc_endpoints(network, "lon", "lat")
gc_endpoints(network, "lon", "lat", distance=FALSE)
gc_endpoints(network, "lon", "lat", keep=FALSE)
## End(Not run)

leonawicz/mapmate documentation built on May 21, 2019, 5:09 a.m.