Skip to content

big edge list to adjacency matrix

3 messages · avinash sahu, Rui Barradas, arun

#
Hello,

The following is a bit convoluted but will do it.


dat <- read.table(text = "
a1 b1 1
a2 b2 2
a3 b3 3
a1 b1 4
a3 b1 5
")

xtabs(V3 ~ V1 + V2, data = aggregate(V3 ~ V1 + V2, data = dat, FUN = max))


Hope this helps,

Rui Barradas

Em 12-03-2013 21:45, avinash sahu escreveu:
#
Hi,

You could also do:
library(reshape2)
?dcast(dat,V1~V2,value.var="V3",max,fill=0)
#? V1 b1 b2 b3
#1 a1? 4? 0? 0
#2 a2? 0? 2? 0
#3 a3? 5? 0? 3


A.K.




----- Original Message -----
From: Rui Barradas <ruipbarradas at sapo.pt>
To: avinash sahu <avinash.sahu at gmail.com>
Cc: r-help at r-project.org
Sent: Tuesday, March 12, 2013 7:10 PM
Subject: Re: [R] big edge list to adjacency matrix

Hello,

The following is a bit convoluted but will do it.


dat <- read.table(text = "
a1 b1 1
a2 b2 2
a3 b3 3
a1 b1 4
a3 b1 5
")

xtabs(V3 ~ V1 + V2, data = aggregate(V3 ~ V1 + V2, data = dat, FUN = max))


Hope this helps,

Rui Barradas

Em 12-03-2013 21:45, avinash sahu escreveu:
______________________________________________
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.