I find myself often writing the following two lines. Is there a succinct alternative?
newObj <- vals
names(newObj) <- nams
# This works, but is ugly and not necessarily preferred
'names<-'(newObj <- vals, nams)
I'm looking for something similar to this (which of course does not work):
newObj <- c(nams = vals)
Wrapping it up in a function is an option as well, but I am wondering if the functionality might already be present.
sample data
vals <- c(1, 2, 3)
nams <- c("A", "B", "C")