Learn R Programming

usefun (version 0.5.2)

prune_and_reorder_vector: 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)

Value

the pruned and re-arranged vector.

Arguments

vec

a vector with names attribute

filter.vec

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

Examples

Run this code
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)

Run the code above in your browser using DataLab