i'm new to coding and I'm trying to perform a network analysis in R. i've got a data frame with 2 columns, one country of origin and the other is destination. I am trying to calculate betweenness and closeness centrality in R. But when trying to graph using :
g <- graph (c2, directed=TRUE)
, where c2
is the name of my DF as described above, I get the message:
Error in graph(c2, directed = TRUE) :
'edges' must be numeric or character.
I've already tried converting factors to characters by the following:
c2 <- data.frame(lapply(c2, as.character), stringsAsFactors=F)
but for some reason it is not helping. What have I done wrong?
edit* - dput(head(c2)) gives:
> dput(head(c2))
structure(list(CountryID.Origin = c("india", "malaysia", "fiji",
"fiji", "china", "united states (the)"), State = c("ACT", "ACT",
"ACT", "ACT", "NSW", "NSW")), row.names = c(NA, 6L), class = "data.frame")