Re: [R] For Social Network Analysis-Graph Analysis - How to convert 2 mode data to 1 mode data?

From: Gabor Csardi <csardi_at_rmki.kfki.hu>
Date: Wed, 14 May 2008 10:01:57 +0200

Please stay on the list.

On Tue, May 13, 2008 at 06:05:15PM -0400, Messing, Solomon O. wrote:
> Gabor,
>
> By the way, this seems to work:

I'm a bit lost. So now you're converting your data frame to a matrix? Why? Or you're doing the two-mode to one-mode conversion here? It does not seem so to me.

Btw. there is a get.adjacency function in igraph to convert a graph to an adjacency matrix.

G.

>
> df.to.nxn <- function( x, y ){
> # x values will be the N x N values
> M <- matrix( nrow = length( unique( x ) ), ncol = length( unique( x
> ) ),

> dimnames = list( unique( x ), unique( x ) ) )
> M[ 1:length( unique( x ) ), 1:length( unique( x ) ) ] <- 0
> # initialize the values to 0
> for( i in 1:length( x ) ) {
> # iterate through rows of data
> index = which( y == y[i] )
> M[ as.character( x[ index ] ), as.character( x[ index ]
> ) ] = 1
> }
> M
> # return M, an N x N matrix
> }

-- 
Csardi Gabor <csardi_at_rmki.kfki.hu>    UNIL DGM

______________________________________________
R-help_at_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.
Received on Wed 14 May 2008 - 09:35:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 17 May 2008 - 15:00:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive