I am searching for the fastest way to union all 100000 list into a dataframe. The union all is not a do.call(rbind) problem because i want to put in one column the output and add the minimum of each list in a group( to better understand the output see my code below).
I have tried two different stuff that works but are pretty slow, so i am searching for something using data.table or dplyr or anything that will make it better .
Example to reproduce what i want :
a <- c(1:3)
b <- c(12:20)
relations <- list(a,b)
output with two different solution that i tried.
1 - solution basically concatenate dataframes with rbind looping on the elements of the list :
full_group <- NULL
for(i in 1:length(relations))
{
full_group = rbind( full_group,
data.frame( id = relations[[i]] ,
group = min( relations[[i]])) )
print(i)
}
2 solution : concatenate vectors and then create a a dataframe out of the results:
full_group <- NULL
groups <- NULL
id <- NULL
for(i in 1:length(relations))
{
id <- c(id , relations[[i]] )
groups <- c( groups , rep( min(relations[[i]]) , length(relations[[i]]) ) )
print(i)
}
full_group = data.frame( id = id ,
groups = groups )