extract_layer_output: Extracts values from layer data and organizes layer-wise...

View source: R/extract_layer_output.R

extract_layer_outputR Documentation

Extracts values from layer data and organizes layer-wise variables in columns

Description

Convenience function to reorganize soil layer time series data from layer_output list entry produced with run_LWFB90. The data is tansformed to a wide format, by casting the variables with the layer number using data.table's dcast-function.

Usage

extract_layer_output(
  x,
  layers = NULL,
  value_vars = NULL,
  layer_index_name = "nl",
  sep = ""
)

Arguments

x

Data.frame or data.table with layer data organized in rows and identified by a layer index column named layer_index_nm.

layers

Integer vector to select a subset of layers. If not supplied, values from all layers will be returned.

value_vars

Character vector containing names of value-variables to be extracted from x. If not supplied, value_vars will be guessed.

layer_index_name

Column containing layer index. Defaults to 'nl' as in layer_output.

sep

Separation character for constructig names from variable name and layer index.

Value

A data.table with the layers' values of the variables organized in columns with the names being made up of the variable name and the layer index.

Examples

# create a data.frame with monthly values
# identifiers: layer number, yr and mo
df <- expand.grid(nl = 1:5,
                  yr = 2002,
                  mo = 1:12)
df

#add a value variable
df$var <- runif(nrow(df), -1,0)

extract_layer_output(df)

# add more variables
df$var1 <- runif(nrow(df), 1,2)
df$var2 <- runif(nrow(df), 2,3)

# extract specific layers
extract_layer_output(df,layers = 2:4, sep = "_layer")

#extract specific variables
extract_layer_output(df, layers = 2:4, value_vars = c("var1", "var2"), sep = "_layer")

pschmidtwalter/LWFBrook90R documentation built on Jan. 27, 2024, 1:48 p.m.