Learn R Programming

supportR (version 1.5.0)

name_vec: Create Named Vector

Description

Create a named vector in a single line without either manually defining names at the outset (e.g., c("name_1" = 1, "name_2" = 2, ...) or spending a second line to assign names to an existing vector (e.g., names(vec) <- c("name_1", "name_2", ...)). Useful in cases where you need a named vector within a pipe and don't want to break into two pipes just to define a named vector (see tidyr::separate_wider_position)

Usage

name_vec(content = NULL, name = NULL)

Value

(named vector) vector with contents from the content argument and names from the name argument

Arguments

content

(vector) content of vector

name

(vector) names to assign to vector (must be in same order)

Examples

Run this code
# Create a named vector
supportR::name_vec(content = 1:10, name = paste0("text_", 1:10))

Run the code above in your browser using DataLab