coords_to_arr: Convert a data frame of coordinates and values to an array.

Description Usage Arguments Value Examples

Description

Given a data frame with columns x1, x2, x3, . . . , xn and a column value, create an array arr of dimension n where arr[x1, x2, . . ., xn] = value.

Usage

1
coords_to_arr(df, missing_value = NA, check_duplicates = TRUE)

Arguments

df

A data frame whose columns are named x1, x2, x3, . . . , xn and value (there can be no other columns). The x columns must be positive integers.

missing_value

Coordinates of arr not specified in df are set to this value (default NA).

check_duplicates

Check for duplicate coordinates in the data frame df, throwing an error if any are present. One reason to turn this off is for speed; the check slows things down slightly. If it's off and df does contain duplicate coordinates, the value associated with the last duplicate coordinate will count.

Value

An n dimensional array with the same type as df$value.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
coords <- tibble::tribble(~x1, ~x2, ~value,
                            1,   1,      3,
                            1,   2,      7,
                            2,   2,      0)
coords_to_arr(coords)
coords <- tibble::tribble(~x1, ~x2, ~ x3, ~value,
                            1,   1,    3,      3,
                            1,   2,    2,      7,
                            2,   2,    1,      0)
coords_to_arr(coords)

rorynolan/brownded documentation built on May 5, 2019, 9:20 a.m.