Reputation: 87
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.
Upvotes: 1
Views: 44
Reputation: 87
The code do.call(cbind, mget(w.list))
worked perfectly, many thanks to Ananda Mahto.
Upvotes: 1