0

I have many data in the global environment. And I want to loop some of them (have a pattern in their names) for calculation. For example, how to (1)select DataX1, DataX2, DataX3 for a loop, and (2)add 1 on them, then (3)storage the result in a new df with name pattern like r.DataX1

DataX1 <- sample(1:10)
DataX2 <- sample(1:10)
DataX3 <- sample(1:10)
DataY1 <- sample(1:10)
DataY2 <- sample(1:10)
DataY3 <- sample(1:10)

list = apropos("DataX.")
for (i in 1:3){
    X <- list[[i]]
    r.DataXi <- X + 1
}

BTW, how to select all the dataframe in the current global environment with a "Y" in the middle, with a "3" at the end, with a "D" at the beginning and loop them?

Thank you.

Beryl
  • 39
  • 5
  • 1
    Suggested duplicate, [How to make a list of data frames?](https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) – Gregor Thomas Feb 27 '20 at 20:56
  • 1
    For your example, `my_list = mget(ls(pattern = "^D.*Y.*3$"))` for starts with D, Y in the middle, 3 at then end. – Gregor Thomas Feb 27 '20 at 20:58

0 Answers0