I have a list of lists, ex.final_list, in which element is a list like below:
final_list[[1]]
`S1`
`S1`[[1]]
"path1" "0.0896894915174206"
`S1`[[2]]
"path2" "0.205873598055805"
....
and so on.
So, I want to have a dataframe with rows as the number of length final_list (which as I mentioned is very large most of the time), and columns number is always 344. In each cell of this dataframe the float number should be saved. There is my code here for doing this:
S_df <- matrix(0, nrow = 42845, ncol = 344)
rownames(S_df) <- unique(names(final_list))
colnames(S_df) <- colnames(paths)
for(i in 1:42845){
print(i)
row_name <- names(final_list[1])
temp_lst <- final_list[[1]]
for(j in 1:length(temp_lst)){
S_df[which(rownames(S_df) == row_name), which(colnames(S_df) == temp_lst[[j]][1])] <- temp_lst[[j]][2]
}
}
This takes a lot time (more than 1 hour and half!!!). Therefore, I would be thankful if anybody has any suggestion for improving the time of my code.