David
> ## an example of row to create the matrix with lists in the cells
> one_row <- rbind( rep( list(rep(list(1),3)) , n) )
> mymat <- do.call( "rbind" , rep( list(one_row) , n) )
>
> ##
> ## The UGGLY loop I would like to improve:
> ##
>
> ## populate the matrix
> k <- 1
> for( i in 1:n){
> ? for( j in 1:n){
> ??? mymat[i,j][[1]] <- list( init_l[[ k ]] )
> ??? k <- k+1
> ? }
> }
>
> colnames(mymat) <- c("X1", "X2", "X3", "X3")
> rownames(mymat) <- c("X1", "X2", "X3", "X4")
>
>
> mymat
>
> # X1???? X2???? X3???? X3
> # X1 List,1 List,1 List,1 List,1
> # X2 List,1 List,1 List,1 List,1
> # X3 List,1 List,1 List,1 List,1
> # X4 List,1 List,1 List,1 List,1
>
>
> #
> # verification, it works
> #
> mymat[2,2]
> init_l[[6]]
>
> ##
> init_l[[6]]
>
> library(tidyverse)
> mymat.t <- as.tibble(mymat)
> mymat.t
> unnest(mymat.t[2,2],cols="X2")[[1]][[1]]
>
> mymat.df <- as.data.frame(mymat)
> mymat.df[2,2][[1]][[1]]
>
>
> thx
>
>
>