I have the following numeric objects:
a1<-12
a2<-10
a3<-8
a4<-7
a5<-21
a6<-34
And I would love to have them as a column in a database. I can easily do:
df<-data.frame(value=c(a1,a2,a3,a4,a5,a6))
but I would love to be able to do it as a sequence. I’ve tryed a few things, like:
df<-data.frame(value=c(paste0("a",1:6)))
or
df<-value=c(get(paste0("a",1:6)))
But none of them put the values into the dataframe.
What is the right approach here?
Thanks!
>Solution :
Since you are getting multiple objects, you should use mget() instead.
df <- data.frame(value = unlist(mget(paste0("a", 1:6))))
value
a1 12
a2 10
a3 8
a4 7
a5 21
a6 34