1
votes

I have multiple vectors of equal length.

w1 <- c(0.61845, 0.65477, 0.68195, 0.71557, 0.74108, 0.76773, 0.78996)
w3 <- c(0.63003, 0.66249, 0.68596, 0.71628, 0.73922, 0.76488, 0.78470) 
w4 <- c(0.51598, 0.54827, 0.57069, 0.59755, 0.61832, 0.64179, 0.65878)

I have another vector containing the names of these vectors as characters.

w.list <- c("w1", "w3", "w4")  

I'm trying to create a matrix of the vectors that are named in w.list.

     w1       w3       w4
0.61845  0.63003  0.51598
0.65477  0.66249  0.54827
0.68195  0.68596  0.57069
0.71557  0.71628  0.59755
0.74108  0.73922  0.61832
0.76773  0.76488  0.64179
0.78996  0.78470  0.65878

Context: I'm automating a process, and I'm left with multiple vectors of equal length with the names w1, w2, w3 etc. However, the vector names do not necessarily follow a constant pattern; it could be w1, w3, w4. Therefore I can't easily define which vectors to add based on a simple formula. My actual data is much bigger.

1
Use a combination of mget and as.data.frame. Or do.call(cbind, mget(w.list)).A5C1D2H2I1M1N2O1R2T1
@AnandaMahto The do.call(cbind, mget(w.list)) worked, thank you for your help. If you submit it as an answer, I'll mark it as the answer.Volcanic
I'm sorry, I'm still rather inexperienced and I don't know how to convert a comment into an answer, unless you mean submit as my own answer?Volcanic

1 Answers

1
votes

The code do.call(cbind, mget(w.list)) worked perfectly, many thanks to Ananda Mahto.