sfn_mutate_at | R Documentation |
Port of mutate_at
for sfn_data
and
sfn_data_multi
objects
sfn_mutate_at(sfn_data, .vars, .funs, ..., solar = FALSE)
sfn_data |
|
.vars |
Variables to mutate. Passed to |
.funs |
Function/s for mutate, passed to |
... |
Extra arguments to pass to the functions in |
solar |
Logical indicating if solar timestamp must used to subset |
'sfn_mutate_at' function will maintain the same number of rows before and
after the modification, so it is well suited to modify variables without
creating TIMESTAMP gaps (i.e. to change variable units). For mutating
individual variables see sfn_mutate
.
For sfn_data
objects, a mutated sfn_data
. For
sfn_data_multi
another sfn_data_multi
with the sites mutated
library(dplyr) library(lubridate) # data data('ARG_TRE', package = 'sapfluxnetr') # transform to NAs any sapflow value occured with wind speed above 25 ws_threshold <- 25 # get the names of the variables to mutate (tree names) vars_to_mutate <- names(get_sapf_data(ARG_TRE)[,-1]) # no TIMESTAMP sfn_mutate_at( ARG_TRE, .vars = vars(one_of(vars_to_mutate)), .funs = list( ~ case_when( ws > ws_threshold ~ NA_real_, TRUE ~ . ) ) ) ## multi data(ARG_MAZ, package = 'sapfluxnetr') data(AUS_CAN_ST2_MIX, package = 'sapfluxnetr') multi_sfn <- sfn_data_multi(ARG_TRE, ARG_MAZ, AUS_CAN_ST2_MIX) ## in multi it's better to discard the variables to not mutate: vars_to_not_mutate <- names(get_env_data(ARG_TRE)) # all the environmental multi_sfn_mutated <- sfn_mutate_at( multi_sfn, .vars = vars(-one_of(vars_to_not_mutate)), # we use - .funs = list( ~ case_when( ws > ws_threshold ~ NA_real_, TRUE ~ . ) ) ) multi_sfn_mutated[['ARG_TRE']]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.