I would like to create a matrix using characters. The characters are names of vectors in a data frame.
df <- data.frame(rnorm(100),rnorm(100),rnorm(100),rnorm(100))
colnames(df) <- c("a1","b1","c1","d1")
a <- paste("df$",names(df), sep = "")
How can I use these characters to reference the data frame and take the data in the vector to a matrix? Something like:
as.matrix(cbind(df$a1,df$b1))
but instead of me writing df$a1,df$b1
these names come from a