Extracts values from layer data and organizes layer-wise variables in columns
Convenience function to reorganize soil layer data such as BELO and SWAT to
the wide format, by casting variables with the layer number, using
data.table's dcast
-function.
extract_layer_output(dat, layers = NULL, value_vars = NULL, sep = "")
dat |
Data.frame with layer data organized in rows and identified by a
layer number column |
layers |
Integer vector addressing the layer numbers (nl) to be extracted from dat. If not supplied, values from all layers will be returned. |
value_vars |
Character vector containing names of value-variables to be
extracted from dat. If not supplied, |
sep |
Separation character for constructig names from variable name and layer index. |
A data.table with the layers' values of the variables organized in columns (wide format) with the names being made up of the variable name and layer number.
# create a data.frame with monthly values # identifiers: layer number, yr and mo df <- expand.grid(nl = 1:5, yr = 2002:2003, 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 = "_") #extract specific variables extract_layer_output(df, layers = 2:4, value_vars = c("var1", "var2"), sep = "_")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.