As part of research I'm doing this semester, I'm adding onto a network that was already built by previous students but I'm running into errors I never had before. This code was not written by me, I have only modified it very slightly as I move along.
So I have this list daily_networks_df
that contains 85953 data frames with each data frame looking something like this:
And the function & code here that generates different sections of the network (home, work, and other):
generate_el <- function(net_df){
networki = net_df[,1]
if(length(networki)>1){
# add edge in all possible pairs with prob_interact[i]
prob_interact=1/sqrt(length(networki))
ppl_pairs = combn(networki, 2)
tmp1 = rbinom(ncol(ppl_pairs), 1, prob_interact)
el_tmp = t(ppl_pairs[,tmp1==1])
return(el_tmp)
}
}
This function above is modified a bit for the 3 different network types but the other 2 are very similar so I didn't include. And here is the function calling:
# DEMAND NETWORK
work_start = 2
list_el1 = lapply(daily_networks_df[1:work_start], generate_el)
gr_el1 = do.call('rbind', list_el1)
# WORK NETWORK
prob_interact = .4
list_el2 = lapply(daily_networks_df[(work_start+1):homes_start], generate_el_work)
gr_el2 = do.call('rbind', list_el2)
# HOME NETWORK
prob_interact = .8
list_el3 = lapply(daily_networks_df[(homes_start+1):length(daily_networks_df)], generate_el_homes)
gr_el3 = do.call('rbind', list_el3)
# FULL NETWORK
gr_el=rbind(gr_el1, gr_el2, gr_el3)
gr = graph_from_data_frame(gr_el, directed=FALSE, vertices=total_pop)
I'm getting this error when I try to execute and have no idea why. Any help?
> gr = graph_from_data_frame(gr_el, directed=FALSE, vertices=total_pop)
Error in make_empty_graph(n = 0, directed = directed) :
VECTOR_ELT() can only be applied to a 'list', not a 'closure'