add some lists to a nested list by loop

I get some data frames with different dimensions from a loop. I would like to save each of these data frames as a list into a big nested list. How can I do it?
Here, I have written a simple incomplete example.

List_a = list()
List_b = list()
 for (i in 1: length(x)) {

list_a [[i]] = W   #After some calculations I will reach "W" which is data frame
List_b = cbind(List_b, List1[[i]])    #how should I write this line?
}
return(List_b)

Thanks in advance

I get some data frames with different dimensions from a loop - an example :

x <- 3:5
for(i in seq_along(x)){
  x_ <- x[i]
  W <- data.frame(matrix(x_,nrow=x_,ncol=x_))
  print(W)
}

expanded above to show how to save each into a list:


x <- 3:5
big_list <- list()
for(i in seq_along(x)){
  x_ <- x[i]
  W <- list(data.frame(matrix(x_,nrow=x_,ncol=x_)))
  big_list <- append(big_list,W)
}

str(big_list)
big_list

please note the use of triple back ticks on a new line

```
code here
```

to format the code.
The forum does not recognise </>

1 Like

Thank you so much :slight_smile:

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.