samedi 22 février 2020

Adding Dataframes to a Bigger Data Frame in R with for Loop

I have two nested for loops (with some if statements inside) in R. The child loop gives me five data frames with one row (in a loop) which is from one file. The parent loop re-does this by selecting another file and creating again five data frame with new data.

The objective is to make a final data frame that every one rowed data frame of the child loop should be added to one big data frame.

I wrote the code and it runs without any error. But the problem is that the resulting data frame (which is supposed to be filled by row in an iterative process) is still empty; While for simple examples like below, it works perfectly.

For example: c is the data frame that I get from the child loop

c= as.data.frame(matrix(data = 1:10, nrow = 1, ncol = 10))

f = 10:50

d = data.frame()

for (i in 1:100) {
  if (i %in% f) {
    d= rbind(c,d)

  }

}

Aucun commentaire:

Enregistrer un commentaire