Watts-College / crj-507-spring-2024

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

"Bill not found" and 'd.mat' not found #15

Closed jjgillis0 closed 7 months ago

jjgillis0 commented 7 months ago

Hello Professor Young~ Below is my code, and I assume it's coming from my URL , but redoing that part still gave me the error: object 'Bill' not found, and when I do the colnames, I get the error: object 'd.mat' not found.

Hopefully, it is an easy fix, but I can't find my error.

Thank you, Jenny

loc2 <- "https://raw.githubusercontent.com/jacobtnyoung/sna-textbook/main/data/data-cocaine-dealing-net.rds" CocaineDealingNet <- readRDS( url(loc2 ) )

look at the network

CocaineDealingNet



<br>

#### 1. Plot the network using the `gplot()` function.    

<br>

```{r}

# Your code here
rm( list = ls() )

d.mat <- rbind(
  c(Bill,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  c( Blacky,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 ),
  c( Bruce,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ),
  c( Charles,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ),
  c( Dante,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0 ),
  c(David,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  c(Donald,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), 
  c(Doug,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  c(Fabio,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  c(Frank,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0),
  c(Steve,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0),
  c(Tommy,0,0,0,0,0,1,1,0,3,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0)
  )
rownames( d.mat ) <- c( "Bill","Blacky","Bruce","Charles","Dante","David","Donald","Doug","Fabio","Frank","Gabriel","Howard","Jenny","Kay","Lara","Lorena","Louis","Marky","Marzio","Menna","Peretta","Peter","Robert","Rosa","Ross","Shawn","Steve","Tommy" )
colnames( d.mat ) <- c( "1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"
                        )
jacobtnyoung commented 7 months ago

Hi @jjgillis0 !

It looks like you are trying to rebuild the matrix "by hand". There are two problems here. First, at the beginning of each line you are calling an object. For example, in the first line R is looking for the object Bill. But this object does not exist. Remember that characters require "", as you do in the rownames command.

But, I am not sure why you are doing this in the first place. All you need to do is download the file using the code below (and in the template):

library( sna )
library( network )

# define the path location for the file
loc2 <- "https://github.com/jacobtnyoung/sna-textbook/raw/main/data/data-cocaine-dealing-net.rds"
CocaineDealingNet <- readRDS( url( loc2 ) )

# plot it
gplot( CocaineDealingNet )

# create an object of matrix
CocaineDealingMatrix <- as.matrix( CocaineDealingNet )

If this code does not work, then you need to recheck your internet connection.

Let me know if that solves the problem!

jjgillis0 commented 7 months ago

Oh thank you! I was thinking it was similar to the undirected network.