| casewhen | R Documentation |
For each position, take the label of the first condition that is TRUE
there. Conditions are a named list of equal-length logical vectors, in the
same shape as collapsevalues()'s groups: the name of an element is the
value used where that element is the first TRUE. Positions matching no
condition get default. NA in a condition counts as not matching.
casewhen(conditions, default = NA)
conditions |
A named list of equal-length logical vectors. Each name
is the value returned where its vector is the first |
default |
Value for positions where no condition holds. Default |
A vector as long as the conditions, holding matched labels and
default elsewhere.
x <- c(-3, 0, 4, 25)
casewhen(list(neg = x < 0, low = x < 10), default = "high")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.