Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to rbind matrices based on objects names?
    text
    copied!<p>I have several matrices that I would like to <code>rbind</code> in a single summary one. They are objects product of different functions and they have share a pattern in their names.</p> <p>What I want to do is to tell R to look for all the objects with that common pattern and then <code>rbind</code> them.</p> <p>Assuming these matrices exist:</p> <pre><code>commonname.N1&lt;-matrix(nrow=2,ncol=3) commonname.N2&lt;-matrix(nrow=2,ncol=3) commonname.M1&lt;-matrix(nrow=2,ncol=3) </code></pre> <p>I tried something like this to get them: </p> <pre><code>mats&lt;-grep(x= ls(pos=1), pattern="commonname.", value=TRUE) mats [1] "commonname.N1" "commonname.N2" "commonname.M1" </code></pre> <p>What I can't figure out is how to tell <code>rbind</code> to use that as argument. Basically I would something that gives the same matrix than what <code>rbind(commonname.N1, commonname.N2, commonname.M1)</code> would do in this example.</p> <p>I have tried things on the line of</p> <pre><code>mats&lt;-toString(mats) rbind(mats2) </code></pre> <p>but that just creates a matrix with the different objects as names. </p> <p>A similar question was asked <a href="https://stackoverflow.com/questions/10269221/how-can-i-expand-a-vector-into-the-arguments-of-a-function-in-r">here</a>, but:</p> <pre><code>mats&lt;-as.list(mats) do.call(what=rbind, args=as.list(mats)) </code></pre> <p>doesn't do the job.</p> <p>Sorry if there is something basic I'm missing somewhere, but I can't figure it out and I'm relatively new to R.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload