partition {funprog} | R Documentation |
Split a vector or a list in 2 groups, given a predicate function.
partition(x, predicate)
x |
vector or list to partition. |
predicate |
a function returning a boolean value, to apply to each element of x. |
A list of two elements. The first element contains elements of x satisfying the predicate, the second the rest of x. Missing values will be discarded.
partition(c(2, 1, 3, 4, 1, 5), function(x) x < 3)
partition(list(1:3, NA, c(1, NA, 3)), anyNA)