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']]
Run the code above in your browser using DataLab