prune_and_reorder_vector: Prune and reorder vector elements

View source: R/operations.R

prune_and_reorder_vectorR Documentation

Prune and reorder vector elements

Description

Given two vectors, the first one's elements are pruned and reordered according to the common values of the second vector and the elements' names (attribute) of the first. If there no common such values, an empty vector is returned.

Usage

prune_and_reorder_vector(vec, filter.vec)

Arguments

vec

a vector with names attribute

filter.vec

a character vector whose values will be used to filter the vec elements

Value

the pruned and re-arranged vector.

Examples

vec = c(1,2,3)
names(vec) = c("a","b","c")

filter.vec1 = c("a")
prune_and_reorder_vector(vec, filter.vec1)

filter.vec2 = c("c", "ert", "b")
prune_and_reorder_vector(vec, filter.vec2)


usefun documentation built on Sept. 15, 2024, 1:06 a.m.