hēRo3 includes a variety of additional R operators that can be used either on their own or inside of functions. These functions are helpful in evaluation of equality or relation and in doing other miscellaneous calculations. A complete listing of these operators and their usage is provided in the table below.
Operator |
Description |
Example |
== |
The equality operator is used to assess whether one variable, constant, or hēRo3 keyword is equal to another. If the first item is equal to the second, this will return TRUE; otherwise it will return FALSE. This operator can be used for time-dependent variables and can return different values for different cycles. |
6 == model_time |
!= | This operator is used to assess whether one variable, constant, or hēRo3 keyword is NOT equal to another. If the first item is NOT equal to the second, this will return TRUE; otherwise it will return FALSE. This operator can be used for time-dependent variables and can return different values for different cycles. |
start_age != current_age |
! | This operator returns the opposite of a logical assessment (ie, if TRUE, this operator would return FALSE). (NOTE: since R evaluates non-zero numbers as TRUE and zero as FALSE, the example to the right would return FALSE.) |
!4 |
>= | This operator assesses if the element on the left side of the operator is greater than or equal to the element on the right side of the operator. |
start_age + model_time >= menopause_age |
> | This operator assesses if the element on the left side of the operator is greater than the element on the right side of the operator. |
model_time > 0 |
<= | This operator assesses if the element on the left side of the operator is less than or equal to the element on the right side of the operator. |
start_age <= current_age |
< | This operator assesses if the element on the left side of the operator is less than the element on the right side of the operator. |
pct_male < pct_female |
&& | This operator examines only the first element and returns a single logical vector. In the example to the right, it evaluates if the first element of x and the first element of y are both TRUE or both FALSE (ie, FALSE in this example). This operator is rarely used. |
x <- c(12, TRUE, FALSE) |
|| | This operator examines only the first element and returns a single logical vector. In the example to the right, it evaluates if the first element of x or the first element of y is TRUE or if both are FALSE (ie, TRUE in this example). This operator is rarely used. |
x <- c(12, TRUE, FALSE) |
& | This operator examines each element and returns a logical vector with a length equal to that of the longer input vector. In the example to the right, it evaluates if the elements of x and the elements of y are TRUE or FALSE (ie, FALSE TRUE FALSE in this example). |
x <- c(12, TRUE, FALSE) |
| | This operator examines each element and returns a logical vector with a length equal to that of the longer input vector. In the example to the right, it evaluates if the elements of x or the elements of y are TRUE or FALSE (ie, TRUE TRUE FALSE in this example). |
x <- c(12, TRUE, FALSE) |
%in% | This operator allows you to compare vectors of different lengths (including a length of one) to see if at least one element of the first vector matches at least one element of the second vector. This can also be used to evaluate whether a value is contained within a table. The output length will equal the length of the first vector being compared (the example to the right would return TRUE). |
a = 7 |