Try this:
m <- matrix(Corr, ncol = 3, dimnames = list(unique(NodesRow),
unique(NodesCol)))
m[col(m) == row(m) | upper.tri(m)] <- NA
subset(as.data.frame.table(m), !is.na(Freq))
On Tue, Jun 8, 2010 at 10:29 AM, Matthew DiLeo wrote:
> I have a large correlation matrix that I'm trying to convert to a list of
> every connection (edge) between every two nodes with its accompanying
> correlation value (for Cytoscape). I figured out how to do this and to
> remove the connections that nodes have to themselves but I can't figure out
> how to get rid of the duplicate pairs (e.g. the edge b-a is a duplicate of
> a-b).
>
>
>
> NodesRow<-rep(c("a","b","c"),each=3)
>
> NodesCol<-rep(c("a","b","c"),times=3)
>
> Corr<-c(1,.8,.4,.8,1,.3,.4,.3,1)
>
> data<-data.frame(NodesRow,NodesCol,Corr)
>
> # above is what my node and edge dataframe looks like
>
> data2<-subset(data,data[,1]!=data[,2])
>
> # above is how I clear out connections nodes have to themselves
>
>
> Thanks for any clues of a better way to do this!
>
>
> Matt
>
>
>
> Matthew DiLeo, Ph.D.
> Postdoctoral Associate
> Boyce Thompson Institute for Plant Research
> Robert W. Holley Center, Tower Road, Ithaca
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]