extractors | R Documentation |
Extract vectors by index or value occurrence
Extract front by first occurrence of a value %[f%
Extract front by last occurrence of a value %[l%
Extract vector front by index %[%
Extract vector rear by index %]%
Extract first occurrence of a value to vector rear %f]%
Extract last occurrence of a value to vector rear %l]%
Extract values at percentile and higher %q]%
Extract values higher than percentile %q)%
Extract values at percentile and smaller %[q%
Extract values smaller than percentile %(q%
Extract first, middle or last value of vector %:%
x %[f% v
x %[l% v
x %[% i
x %]% i
x %f]% v
x %l]% v
x %q]% q
x %q)% q
x %[q% q
x %(q% q
x %:% j
x |
A vector |
v |
A value of which the first or last occurrence in |
i |
An index or two element vector |
q |
A percentile value (between |
j |
A character indicating to extract the first |
A vector extracted from the front, rear, or, range of x
. Either based on an index or the first or last occurrence of a value or the first, middle, or, last element of a vector.
The function provided for symmetry, character lengths of x%]%i
and x[1:i]
are equal.
z <- letters
# Extract front by first occurrence of value
z %[f% "n"
# Extract front by index
x <- rnorm(100)
x %[% 10
# Extract rear by index
x %]% 90
# Extract rear by index
x %]% 90
# Extract by indices if a range is provided
x %]% c(4,30)
z %[% c(6,10)
# Extract last/middle value of x
x %:% "l"
z %:% "m"
# Extract by percentile
seq(1,10,.5) %(q% .5 # infix
seq(1,10,.5)[seq(1,10,.5) < quantile(seq(1,10,.5),.5)] # regular syntax
seq(1,10,.5) %q]% .5 # infix
seq(1,10,.5)[seq(1,10,.5) >= quantile(seq(1,10,.5),.5)] # regular syntax
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.