Description Usage Arguments Details Value
This will return all starting locations of the needle found within the haystack - even overlapping ones.
1 2 3 4 5 | locate(needle, haystack, alignment = NA_integer_)
cached_locate(needle, haystack, alignment = NA_integer_)
locate_next(needle, haystack, start = 1L, alignment = NA)
|
needle |
vector of values |
haystack |
vector of values |
alignment |
search must start at a multiple of this index location (+1). Useful for
byte-aligned searches of bit vectors i.e. |
start |
lowest index to accept |
The routine is pretty relaxed about types so you can search for an integer vector within a character vector if you so choose.
Supported types:
all built-in atomic types in R i.e. integer, numeric, real, character, complex, raw
bit
type from the bit
package - Note: in order to
search for the matches, 'bit' objects are basically extracted to
their equivalent logical vector causing higher memory usage
and negating any memory savings of using 'bit'.
locate
is the core location function. There is no cacheing, so identical searches
are started from scratch each time.
cached_locate
is a memoised version of locate
. Because calling
locate
can be quite an expensive operation, searches for a given
sequence in a haystack are cached to save time on subsequent calls.
locate_next
gives the first index on, or after, the given start
index.
Adapted from code originally written by carroll_jono - https://twitter.com/carroll_jono
Indices of the start of all occurrences of needle in haystack, or NA if no matches found.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.