partition: Partition a vector in two

Description Usage Arguments Value Examples

View source: R/partition.R

Description

Split a vector or a list in 2 groups, given a predicate function.

Usage

1
partition(x, predicate)

Arguments

x

vector or list to partition.

predicate

a function returning a boolean value, to apply to each element of x.

Value

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.

Examples

1
2
partition(c(2, 1, 3, 4, 1, 5), function(x) x < 3)
partition(list(1:3, NA, c(1, NA, 3)), anyNA)

funprog documentation built on Jan. 13, 2021, 11:52 a.m.