Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as.matrix with a bipartite network object does not return a matrix #69

Closed
leifeld opened this issue Apr 1, 2022 · 2 comments
Closed

Comments

@leifeld
Copy link

leifeld commented Apr 1, 2022

See here for a case where a bipartite network object with a single second-mode node cannot be converted to a matrix using as.matrix. Not sure if that's related to #64, but perhaps worth addressing together?

@leifeld
Copy link
Author

leifeld commented Apr 1, 2022

For completeness, a self-contained and replicable version of the example the user provided:

library("dplyr")
library("network")

node_vars <- data.frame(
  name = c("Actor 1", "Actor 1", "Actor 2", "Actor 2", "Actor 3", "Actor 3"),
  var1 = c("A", "A", "A", "A", "A", "B"),
  year = c(2000, 2001, 2000, 2001, 2000, 2001),
  type = c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE)
)

node_var_list <- node_vars %>%
  group_by(year) %>%
  group_split()

edge_vars <- data.frame(
  name1 = c("Actor 1", "Actor 1", "Actor 1"),
  name2 = c("Actor 2", "Actor 2", "Actor 3"),
  year = c(2000, 2001, 2000)
)

edge_var_list <- edge_vars %>%
  group_by(year) %>%
  group_split()

test_net1_bp <- as.network(x = edge_var_list[[1]], vertices = node_var_list[[1]],
                           directed = FALSE, bipartite = TRUE, bipartite_col = "type")

test_net2_bp <- as.network(x = edge_var_list[[2]], vertices = node_var_list[[2]],
                           directed = FALSE, bipartite = TRUE, bipartite_col = "type")

class(as.matrix(test_net1_bp)) # not a matrix

dim(as.matrix(test_net1_bp)) # returns NULL

@krivit
Copy link
Member

krivit commented Apr 20, 2022

Thanks for the report! Looks like a dimension is being dropped somewhere where it shouldn't be.

@krivit krivit closed this as completed in 27c8857 May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants