Skip to content

Instantly share code, notes, and snippets.

View chaoneng's full-sized avatar
🤫

Charles C.N. Wang chaoneng

🤫
View GitHub Profile
Key Sublime Text 3.2.1 Build 3207
----- BEGIN LICENSE -----
Member J2TeaM
Single User License
EA7E-1011316
D7DA350E 1B8B0760 972F8B60 F3E64036
B9B4E234 F356F38F 0AD1E3B7 0E9C5FAD
FA0A2ABE 25F65BD8 D51458E5 3923CE80
87428428 79079A01 AA69F319 A1AF29A4
A684C2DC 0B1583D4 19CBD290 217618CD
#Network Analysis-Node-level Calculations
library(igraph)
el=as.matrix(read.csv("~/desktop/interactions.csv"))#read.csv(file.choose()
el[,1]=as.character(el[,1])#Because the vertex IDs in this dataset are numbers, we make sure igraph knows these should be treated as characters. Otherwise, it'll create problems.
el[,2]=as.character(el[,2])
g=graph.edgelist(el)
a=get.adjacency(g,sparse=FALSE)
#Network analysis-interaction
library(igraph)
dat=read.csv(file.choose(),header=TRUE) # choose an edgelist in .csv file format
el=as.matrix(dat) # coerces the data into a two-column matrix format that igraph likes
el[,1]=as.character(el[,1])
el[,2]=as.character(el[,2])
g=graph.edgelist(el,directed=FALSE) # turns the edgelist into a 'graph object'
a=get.adjacency(g,sparse=FALSE)