Notes‎ > ‎

Failed R experiments #29123

posted 2 Jun 2012, 08:32 by David Sherlock   [ updated 2 Jun 2012, 08:41 ]

R is a difficult place to start learning something new. I’m currently writing a beginners guide to Complex Networks and made the mistake of going down the route of learning some of the basics in R. As every programmer knows you only real learn through failing and documenting them is just as important (if not more important) as documenting your success.

Problem: Had a two column dataset that I wanted to turn into a one mode model graph in Complex Network analysis software. Attempted to do it in R. Thought I would start with something visual.

This was the code:

setwd("/Users/David/Desktop/PhD/R_github/ROI")

projectDir = getwd() 

codeDir = file.path(projectDir, 'code')

dataDir = file.path(projectDir, 'data')

outputDir = file.path(projectDir, 'output')

 

VERBOSE=TRUE

if (VERBOSE)

  print("Verbose SET")

 

organisations_events<-read.csv("/Users/David/Desktop/PhD/R_github/ROI/data/Ins_Event.csv" , header=T, sep=",")

df<-read.csv("/Users/David/Desktop/PhD/R_github/ROI/data/Ins_Event.csv" , header=T, sep=",")

M = as.matrix( table(df) )

Mrow = M %*% t(M)

Mcol = t(M) %*% M

iMrow <- graph.incidence(Mrow, mode=c("all") )

V(iMrow)$label = V(iMrow)$name

V(iMrow)$label = V(iMrow)$name

V(iMrow)$label.color = rgb(0,0,.2,.5)

V(iMrow)$label.cex = .4

V(iMrow)$size = 6

V(iMrow)$frame.color = V(iMrow)$color


 plot(iMrow, layout=layout.fruchterman.reingold)

 

 This was the result:

 

 

 

Whoops.


In fairness I had created two relationship matrixs correctly, which was an achivement for me myself:

M = as.matrix( table(df) )

Mrow = M %*% t(M)

Mcol = t(M) %*% M


Maybe I should jump ship to another tool from that bit. Perhaps some help here: http://www.online-pr.com/Holding/Social_Network_analysis_article.pdf


Comments