Hold or Toss
Arguments
- x
A vector of values
- i
An indication of which subset values to action. This can be a logical vector, an integer vector, or a function that takes
xas an argument and returns a logical or integer vector- na
How to handle
NAvalues in whenpis a logical vector, or a function that returns a logical vector.hold()defaults to droppingNAvalues, whiletoss()defaults to keepingNAvalues. Whenpis an integer vector,NAvalues are always dropped.
Examples
x <- c(1, NA, 3, 4, Inf, 6)
twos <- function(x) x %% 2 == 0
hold(x, twos) # 4, 6
#> [1] 4 6
toss(x, twos) # 1, 3, NA, Inf
#> [1] 1 NA 3 Inf
hold(x, twos, na = "keep") # NA, 4, Inf, 6
#> [1] NA 4 Inf 6
toss(x, twos, na = "drop") # 1, 3
#> [1] 1 3
i <- c(1:3, NA)
x <- letters[1:5]
hold(x, i)
#> [1] "a" "b" "c"
toss(x, i)
#> [1] "d" "e"
