0

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:

enter image description here

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'
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It's unclear what's stored in the `gr_el1` , `gr_el2`, `gr_el3`, and `total_pop` variables. Chances are one has something unexpected. – MrFlick May 11 '21 at 20:06
  • Thank you for the tip! I've just edited the post. – Asha Collie May 11 '21 at 20:29
  • Please don't post data as an image. Use a `dput()` or something else as described in the provided link so we can copy/paste code into R to test it. It's a lot of work to retype all that just to try to help you. – MrFlick May 11 '21 at 20:31
  • Could you `dput(daily_networks_df[[20]])` and paste the output to your post? – ThomasIsCoding May 12 '21 at 08:10

0 Answers0