extract_layer_output {LWFBrook90R} | R 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 |
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 |
layer_index_name |
Column containing layer index. Defaults to 'nl' as in
|
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")