I want to create a data frame from a series of vectors that I have named like d*i*
. I attempted to do this using the paste function, but it just built a data frame with a single column with values "d1, d2, d3..." I want to put the vectors associated with those variable names in. How do I do this?
d1 <- c(6.3,8.3,6.6,0,8.4,8.6)
d2 <- c(8.2,8.7,8.6,7.9,7.1,7.6)
d3 <- c(7.1,6.4,6.6,8,7.5,10.3)
d4 <- c(8,7.7,7.3,0,9.4,6.4)
d5 <- c(8.5,6.8,0,0,7.3,9.7)
d6 <- c(5.9,7.5,6.5,0,9.8,7.8)
d7 <- c(7.6,5.3,6.7,0,6.6,7.4)
d8 <- c(9.5,5.6,8.8,0,8.6,8.3)
d9 <- c(8.5,7.4,0,0,9.2,8.6)
d10 <- c(7.8,6.9,8.6,6.7,6.8,6.1)
mydata <- data.frame(paste("d",1:10))
You can do this:
my_data = as.data.frame(mget(paste0("d", 1:10)))
Though you should probably think about not creating sequentially named variables in the first place--maybe put them in a data frame or a list directly.