getXY: Easy and Flexible Input for One- and Two Dimensional Data

Description Usage Arguments Details Value Author(s) Examples

View source: R/getXY.R

Description

The function accepts one- or two dimensional data, checks them for compatibility and gives a dataframe back.

Usage

1
getXY(x, y = NULL, unidim.allowed = TRUE)

Arguments

x

Vector, matrix, dataframe or list. If x is a vector, the second dimension may be defined by argument y. If x is a matrix, dataframe or list and a second column or element exists, this second element is used instead of y.

y

Optional vector of the same length as x.
When argument x is onedimensional, argument y does not exist and unidim.allowed is TRUE, argument x is coerced to a vector and returned as y component where the resulting x is just the index vector 1:n.

unidim.allowed

Logical.
When unidim.allowed is TRUE (=default), one and two dimensional input is accepted for any reasonable combination of x and y. In this mode getXY behaves very similar to xy.coords
An error message is returned, when unidim.allowed is FALSE, argument x is onedimenional und y does not exist.

Details

Input is checked for compatibility: When x is a list, the first two elements must have identical length. When y is defined, x must be one dimensional and must have the same length as argument y. When onedim.allowed is FALSE, input must be twodimensional.

When input is one dimensional and unidim is TRUE, y gives the numbers of elements back.

Function works similar to xy.coords

Value

dataframe with the components x and y

Author(s)

Rene Locher

Examples

1
2
3
4
5
getXY(3:4, 1:2)
getXY(matrix(1:4,ncol=2))
getXY(as.data.frame(matrix(1:4,ncol=2)))
getXY(4:1)
getXY(list(a=1:2,b=9:10))

IDPmisc documentation built on Jan. 21, 2020, 5:06 p.m.