'error with the result of a replication procedure

I have a problem with the following procedure:

library(igraph)
k <- cbind(c(.2,.2),c(.2,0))

sbm_centr <- replicate(
  2000,
  sample_sbm(49, pref.matrix = k, block.sizes = c(24, 25)) %>%
    centr_degree(.)$centralization
)

The issue is that the function generates a result with two arguments (in addition to the ID of each replication), so the procedure reports an error: Error in .$centr_degree(.) : 3 arguments passed to '$' requiring 2"

I tried, unsuccessfully, to save one of the arguments with the following expression: centr_degree(.)$centralization[1])

But the list contains only 0s. Thanks in advance for your comments.



Solution 1:[1]

We can use [[ in the pipe like below

sbm_centr <- replicate(
  1,
  sample_sbm(49, pref.matrix = k, block.sizes = c(24, 25)) %>%
    centr_degree(.) %>%
    `[[`("centralization")
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ThomasIsCoding