r - How to rbind matrices based on objects names? -
i have several matrices rbind in single summary one. objects product of different functions , have share pattern in names.
what want tell r objects common pattern , rbind them.
assuming these matrices exist:
commonname.n1<-matrix(nrow=2,ncol=3) commonname.n2<-matrix(nrow=2,ncol=3) commonname.m1<-matrix(nrow=2,ncol=3) i tried them:
mats<-grep(x= ls(pos=1), pattern="commonname.", value=true) mats [1] "commonname.n1" "commonname.n2" "commonname.m1" what can't figure out how tell rbind use argument. gives same matrix rbind(commonname.n1, commonname.n2, commonname.m1) in example.
i have tried things on line of
mats<-tostring(mats) rbind(mats2) but creates matrix different objects names.
a similar question asked here, but:
mats<-as.list(mats) do.call(what=rbind, args=as.list(mats)) doesn't job.
sorry if there basic i'm missing somewhere, can't figure out , i'm relatively new r.
use mget:
do.call(rbind,mget(mats))
Comments
Post a Comment