Description Usage Arguments Details Value See Also Examples
member.if
and member.if.not
search "sequences" (by which we
mean lists, other vectors or pairlists) for the first element satisfying
some predicate function, and return the sub-sequence beginning with that
element. member.if.not
uses Negate(f) as its predicate.
1 2 3 | member.if(f, x, k = identity)
member.if.not(f, x, k = identity)
|
f |
The filter predicate to use on the sequence x. |
x |
The sequence to search for a satisfying element. |
k |
The "key" function to pre-apply to elements of x. Defaults to the identity function. |
The sequence searched is actually map(k, x)
rather than x,
which makes it easier to avoid defining short anonymous functions.
The tail of the sequence map(k, x)
beginning with the first
element that satisfies the predicate f, or NULL if no element did.
The functional-programming functions in base, especially Filter
,
under funprog
.
1 2 3 4 5 6 7 | f <- 20:40
#The first element divisible by 3 and all afterward
member.if(is.zero, f, k=function(x) x %% 3) == 21:40
#Trimming by the presence of a sentinel value
member.if.not(function(x) x < 30, f) == 30:40
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.