Watts-College / crj-507-spring-2024

https://watts-college.github.io/crj-507-spring-2024/
MIT License
1 stars 0 forks source link

Errors with colSums() and rowSums() - Lab 3 #6

Closed jesscowart closed 7 months ago

jesscowart commented 7 months ago

I am trying to calculate the degree for each actor for the undirected binary graph, but when I run colSums() or rowSums(), it gives me an error: 'x' must be an array of at least two dimensions.

Here is my code:

gplot( LondonGangNet, gmode = "graph", main = "London Gang Network" )
colSums(LondonGangNet)
rowSums(LondonGangNet)
jacobtnyoung commented 7 months ago

Hi @jesscowart! The LondonGangNet object is one of class network. The colSums() and rowSums() functions needs an object of class matrix. You can address this in two ways.

First, you can coerce the object to a matrix like this:


colSums( as.matrix( LondongGangNet ) )

Or, you can use the degree() function in the sna package.

Let me know if you are still experiencing issues!

jesscowart commented 7 months ago

Thank you!

jacobtnyoung commented 7 months ago

Your welcome!

jacobtnyoung commented 7 months ago

I am reopening this issue so that others can see it in case it pertains to them.