hēRo3 includes a variety of additional R functions that can be used either on their own or inside of other functions. A complete listing of these operators and their usage is provided in the table below.
Operator |
Description |
Example |
any(...) |
This function evaluates if, among a set of logical vectors (ie, a table of values or a list of values or a single value), any of said vectors are TRUE. In the example to the right, if the life table includes values above 100, this function would evaluate as TRUE; otherwise, it would evaluate as FALSE. |
any(Life_Table > 100) |
all(...) | This function evaluates if, among a set of logical vectors (ie, a table of values or a list of values or a single value), all of said vectors are TRUE. In the example to the right, this function would evaluate as FALSE. |
m <- c(0.1, 1.7, 2.4, 3.1, 0.8) |
is.na(...) | This function evaluates each element of a vector to determine if said element is N/A. The length of the output will be equal to the length of the input vector. |
is.na() |
if(...) else | This function evaluates a logical test and if TRUE uses the first value and if FALSE uses the second value. This function should be used if the values being returned are tables or survival distributions. The condition being checked with this function cannot be time-dependent. |
if(a == "yes") Life_Table else Life_Table_2 |
ifelse(...) | This function evaluates a logical test and if TRUE uses the first value and if FALSE uses the second value. This function should be used if the values being returned are parameters or constants. |
ifelse(model_time == 1, initial_cost, 0) |
switch(...) |
This function evaluates multiple checks and returns values based on those checks. Unlike either of the "if" "else" functions, this function is not limited as an either or type function and it can evaluate more than one logical test. This function may be used to determine a distribution to use based on the value of a flag with multiple possible values. Each argument name corresponds to a potential value for flag, and the argument value corresponds to the value that will be used in that case. (NOTE: flag being checked cannot be time-dependent.) |
switch(dist_flag[1], |