How to add named element to vector R named from variable
I want to add an element, say 100, to the vector V and use the value of the variable x as the new element name. I know it can be done like this:
V = c(V, 100) names(V)[length(V)] = x
but I'm looking for a simple one line solution if there is one. I tried:
V = c(V, as.name(x)=100)
and
V = c(V, eval(x)=100)
but they don't work.
+3
source to share
2 answers