cbind over 100 R objects

Hi all!

I would like to cbind over 100 R objects and I would like to do this automatically rather than entering the >100 names of the R objects that I made in the script.

Example of the object names
Rhine_d1 <- sum(...)
Rhine_d2 <- sum(...)
Rhine_m1 <- sum(...) - Rhine_d2
Rhine_u <- sum(...)
Meuse_d1 <-
Meuse_d2 <-

Is there any way that I can refer to, for instance script line 100:250 for the cbind function?

Thank you!

I would first off think about the structure of your code and if you need that many standalone vars, maybe refactoring it to data.frame or so would be better? Anyway you could do something like this (only in a script though!):

Rhine_d1 <- sum(1,1)
Rhine_d2 <- sum(2,2)
Rhine_m1 <- sum(3,3) - Rhine_d2

env <- ls(.GlobalEnv)

var_names <- env[grepl("^Rhine_.*",env)]

bound <- data.frame(cbind(mget(var_names)))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.