Convert to named list

as_named_list(x, names, sep = ".")

Arguments

x

[vector]
Vector to be converted.

names

[character]
Either a single character or vector of length(x) characters.

sep

[string]
Single character used to split name from consecutive numbers in terms that names is a single character.

Value

A named list.

Examples

x = 1:3 as_named_list(x, names = "x", sep = "-")
#> $`x-1` #> [1] 1 #> #> $`x-2` #> [1] 2 #> #> $`x-3` #> [1] 3 #>
as_named_list(x, names = "x")
#> $x.1 #> [1] 1 #> #> $x.2 #> [1] 2 #> #> $x.3 #> [1] 3 #>
as_named_list(x, names = c("e1", "e2", "e3"))
#> $e1 #> [1] 1 #> #> $e2 #> [1] 2 #> #> $e3 #> [1] 3 #>