stcoords: Spatiotemporal data formatting

View source: R/coords.R

stcoordsR Documentation

Spatiotemporal data formatting

Description

Format spatiotemporal series in a unified manner for both 1D and 2D locations. If x is a data frame or matrix, y and t are omitted.

Usage

stcoords(x, y = NULL, t = NULL, unite.xy = FALSE, unite.sep = "_")

Arguments

x

A vector, data frame or matrix.

y

A vector.

t

A vector.

unite.xy

A boolean indicates if merging x and y coordinates into a string to represent a unique location.

unite.sep

A separator to use between x and y coordinates.

Details

If x is a data frame (3 columns), this function automatically identify spatial and temporal values by column names, i.e., (x,y,t) and (lat,lon,time). Otherwise, the column indexes are employed as [, 1] and [, 2] being the space coordinates and [, 3] being the timestamps.

If x is a data frame (2 columns), similar policies are involved, but alternatively column names (x, t) and (loc, time) are used.

If x is a matrix, column indexes are used merely.

If x is a vector, dimensions of space coordinates are determined by both x and y, and the time dimension by t.

Value

A list of formatted location sequences: is_1d: boolean, indicate the spatial coordinates are 1D or 2D. x: a vector of x coordinate. y: a vector of y coordinate, NULL if unite.xy is TRUE t: a vector of timestamps.

Examples

## One data frame with columes x, y, t
x <- data.frame(x=rep(1:10, 2), y=rep_each(1:10, 2), t=1:20)
stcoords(x)

## One data frame without demanded colume names
x <- data.frame(rep(1:10, 2), rep_each(1:10, 2), 1:20)

## One data frame with two columes loc, time
x <- data.frame(loc=rep(1:10, 2), time=1:20)

## With vectors
stcoords(x=rep(1:10, 2), t=1:20)

## Combine x and y coordinates
x <- data.frame(rep(1:10, 2), rep_each(1:10, 2), 1:20)
stcoords(x, unite.xy=TRUE)

caesar0301/movr documentation built on June 18, 2022, 2:37 a.m.