Looping and Nested Looping in R with Multiple Dataset

Viewed 19

I have 24 dataset and all columns are same. I wanna ask about looping and nested looping and making new variable while looping

Let me give example:

data_1 <- data.frame(ID = c(123, 234, 345, 456), Block_Code = c("D", "U", "Z", "G"),
                     DPP = c(1,2,3,4))

data_2 <- data.frame(ID = c(123, 234, 345, 456, 678), Block_Code = c("Z", "G", "T", "D", "U" ),
                     DPP = c(2,3,1,4,5))

data_3 <- data.frame(ID = c(123, 234, 345, 456,678,124), 
                     Block_Code = c("U", "Z","G","T", "D","R"),DPP = c(6,2,2,4,5,6))

data_4 <- data.frame(ID = c(123, 234, 345, 456, 678, 124, 567), Block_Code = c("D", "U", "Z", 
                     "G","T","R","Z"),DPP = c(1,2,3,4,5,6,7))

data_5 <- data.frame(ID = c(123, 234, 345, 456, 678, 124, 567, 256), Block_Code = c("D", "U", "Z", 
                     "G","T","R","Z","U"), DPP = c(1,2,3,4,5,6,7,8))

data_6 <- data.frame(ID = c(123, 234, 345, 456, 678, 124, 567, 256, 345), Block_Code = c("D", "U", 
                    "Z", "G","T","R","Z","U", "Z"),DPP = c(1,2,3,4,5,6,7,8,2))

data_7 <- data.frame(ID = c(123, 234, 345, 456,  678, 124, 567, 256, 345, 647), Block_Code = 
                     c("D", "U", "Z", "G","T","R","Z","U", "Z","S"), 
                     DPP = c(1,2,3,4,5,6,7,8,2,12)))

and so on until data_24

And the result like that for example 2 dataset enter image description here

So the looping from data_1 until data_24 and the nested looping is (example looping data_1 and the nested looping for only data_1 is 3 dataset after that so like the example data_2,data_3,data_4. Also for looping data_2 the nested looping is 3 dataset after, are data_3, data_4,data_5) and so on until looping data_20.

and then after that looping, I view each dataset, it will be like the picture.

Thank you for helping. I just know the basic looping and dont know how to work with multiple data frames

0 Answers
Related