geardf {gear}R Documentation

Construct a geardf

Description

geardf constructs a geardf, which is simply a data.frame with an attribute indicating which columns refer to the coordinates. The function either combines x and coords if coordnames isn't provided, or identifies the columns of x to which coordnames refers. The geardf class is only provided to make plotting results of the predict.geolm* functions simple without depending on the sp or sf packages. See plot.geardf for easy plotting.

Usage

geardf(data, coords, coordnames)

Arguments

data

A data.frame

coords

A data.frame or matrix with column names

coordnames

The columns of data containing the spatial coordinates, provided as a formula (e.g., ~ x + y), column numbers (e.g., c(1, 2)), or column names (e.g., c("x", "y")). The default is NULL.

Value

A geardf

See Also

plot.geardf

Examples

dtf = data.frame(a = 1:2, b = 3:4)

# create geardf with matrix coords (note column names)
coords = matrix(rnorm(4), ncol = 2)
colnames(coords) = c("u", "v")
geardf(dtf, coords)

# create geardf with data.frame coords
coords = as.data.frame(coords)
geardf(dtf, coords)

# create geardf using coordnames
dtf2 = cbind(dtf, u = rnorm(2), v = rnorm(2))
# vector form of coordnames
geardf(dtf2, coordnames = c("u", "v"))
# formula form of coordnames
geardf(dtf2, coordnames = ~ u + v)
# column index forum of coordnames
geardf(dtf2, coordnames = 3:4)

gdf = geardf(dtf2, coordnames = 3:4)
# looks like a data.frame
gdf
# but slightly more complicated
class(gdf)
attr(gdf, "coordnames")

[Package gear version 0.3.4 Index]