Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create a dataframe with objects containing single values

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading