I have a list of matrices that have been extracted from a larger network using the egoextract function from R's 'network' package. I need to merge all the (square) matrices, which have different numbers of rows/columns into one larger matrix containing all the information of the previous ones and 'NA's for places where the information is missing (which is ok).
I tried cbindX function but it only does it along the column dimension and not the rows, so the product is a rectangular matrix.
This is what I've done so far
require(network)
require(statnet)
require(gdata)
samplenet <- as.network.numeric(100, directed = TRUE, density = 0.03)
plot(samplenet)
set.vertex.attribute(samplenet, "name", 1:100)
names <- get.vertex.attribute(samplenet, "name")
rv1 <- sample(names,1) #selects a random vertex
rv2 <- get.neighborhood(samplenet, rv1, type = c("combined"), na.omit = TRUE) #selects the neighborhood around selected vertex
rv <- unique(unlist(merge(rv1, rv2))) #combines vertex + neighborhood into one list without duplicates
extraction <- unique(ego.extract(samplenet, ego = rv, neighborhood = c("combined")))
df <- data.frame(extraction) -- error due to different number of rows/columns
Alternative (leads to rectangular matrix, which is not sufficient)
df <- cbindX(extraction[[1]], extraction[[2]], extraction[[3]])
Thank you awesome R community!!!