Learn R Programming

glmmboot (version 0.6.0)

gen_vector_match: Finds all occurrences of new_vector in orig_vector

Description

For each value in new_vector, we find the indices of ALL matching values in orig_vector. This means that if new_vector has duplicates, we'll duplicate the indices from orig_vector too

Usage

gen_vector_match(orig_vector, new_vector, current_index = vector("integer", 0))

Arguments

orig_vector

Vector to find indices from.

new_vector

Vector to match values to (from orig_vector).

current_index

Accumulator of the indices so far, for recursion.

Value

Returns a vector of indices from orig_vector that correspond to values in new_vector.

Examples

Run this code
# NOT RUN {
    orig_vector <- c(1, 1, 2, 3, 3, 3)
    new_vector <- c(1, 2, 1)

    vector_match <- gen_vector_match(orig_vector, new_vector)
    ## testthat::expect_equal(vector_match, c(1, 2, 3, 1, 2))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab