Learn R Programming

mcgf (version 1.1.1)

dists.mcgf: Calculating distance matrices for an mcgf object

Description

Calculating distance matrices for an mcgf object

Usage

# S3 method for mcgf
dists(x, return_grid = FALSE, ...)

dists(x) <- value

Value

A list of signed distance matrices: h (Euclidean), h1

(horizontal), and h2 (vertical).

Arguments

x

An mcgf object.

return_grid

Logical; used when locations in x are longitudes and latitudes.

...

Additional parameters or attributes.

value

List of signed distance matrices, outputted from dists().

Details

If the dists attribute is available in x, it will be printed. Otherwise dists will be calculated based on the locations attribute.

Examples

Run this code
data <- cbind(S1 = 1:5, S2 = 4:8, S3 = 5:9)
lon <- c(110, 120, 130)
lat <- c(50, 55, 60)
locations <- cbind(lon, lat)

# if locations are longitudes and latitudes
obj <- mcgf(data = data, locations = locations)
obj
dists(obj)
dists(obj) <- dists(obj)
obj

# if locations are just coordinates in a 2D plane:
obj <- mcgf(data = data, locations = locations, longlat = FALSE)
obj

# calculate distances
dists(obj)

# add distances to the `mcgf` object
dists(obj) <- dists(obj)
obj

Run the code above in your browser using DataLab