Prepare a parameter-long data frame for statistical analysis

nested_data(
  .data,
  qualifiers = NULL,
  key = NULL,
  value,
  fill = NA,
  select_if = ~TRUE,
  filter_all = any_vars(TRUE),
  trans = identity,
  groups = NULL
)

unnested_data(.data, ...)

Arguments

.data

Data in parameter-long form

qualifiers

Columns that add context to observations (e.g., depth, zone, core)

key

The column name that contains the column names of the data matrix

value

The column name that contains the values

fill

If a key/value combination doesn't exist in the input, this value will be assigned in the data matrix. Generally, using NA for geochemical data and 0 for relative abundance data is advised.

select_if

Use ~TRUE to keep all columns; use ~all(is.finite(.)) to keep columns with all finite values. See select_if.

filter_all

Use any_vars(TRUE) to keep all observations; use all_vars(is.finite(.)) to keep only observations with finite (non-missing) values. See filter_all.

trans

A function that will be applied to all columns, column-wise. Use identity to perform no transformation, use scale to scale each column to a mean of zero and variance of 1. See mutate_all.

groups

Use group_by or this argument to group by one or more columns (e.g., core or lake)

...

One or more columns to unnest.

Value

A nested data matrix, which is composed of a tibble::tibble()

with tibble list-columns data, discarded_rows, discarded_columns, and qualifiers.

Examples

nested_data(
  alta_lake_geochem,
  qualifiers = c(age, depth, zone),
  key = param,
  value = value,
  trans = scale
)
#> # A tibble: 1 × 4
#>   discarded_columns discarded_rows   qualifiers        data             
#> * <list>            <list>           <list>            <list>           
#> 1 <tibble [32 × 0]> <tibble [0 × 9]> <tibble [32 × 4]> <tibble [32 × 6]>