[R] Transforming relational data
mathijsdevaan
mathijsdevaan at gmail.com
Fri Feb 18 08:07:19 CET 2011
OK, for the last step I have tried this (among other things):
library(data.table)
DT = data.table(read.table(textConnection(" A B C
1 1 a 1999
2 1 b 1999
3 1 c 1999
4 1 d 1999
5 2 c 2001
6 2 d 2001
7 3 a 2004
8 3 b 2004
9 3 d 2004"),head=TRUE,stringsAsFactors=FALSE))
firststep = DT[,cbind(expand.grid(B,B),v=1/length(B)),by=C][Var1!=Var2]
setkey(firststep,Var1,Var2)
list1<-firststep[J(expand.grid(DT$B,DT$B),v=1/length(DT$B)),nomatch=0][,sum(v)]
list1
#27
What I would like to get:
list
1 0
2 0.5
3 2.5
Thanks!
--
View this message in context: http://r.789695.n4.nabble.com/Re-Transforming-relational-data-tp3307449p3312140.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list