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. ______________________________________________ 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.