OK, I'm pre-coffee, but what's wrong with using upper.tri to create a new
matrix and then multiplying that matrix by the original "dat" matrix (direct
multiplication, not matrix multiply) to get the desired answer?
Bert Gunter wrote
> I believe matrix indexing makes Arun's complex code wholly unn
I believe matrix indexing makes Arun's complex code wholly unnececessary:
Starting with dat1 as above:
m <- matrix(0,4,4)
m[as.matrix(dat1[,1:2])] <- dat1[,3]
## yielding:
m
[,1] [,2] [,3] [,4]
[1,]0211
[2,]0121
[3,]0002
[4,]000
Hi,
May be this helps:
dat1 <- read.table(text="
data data freq
1 2 2
1 3 1
1 4 1
2 3 2
2 4 1
2 2 1
3 4 2",sep="",header=TRUE)
val<- unique(c(dat1[,1],dat1[,2]))
dat2 <-expand.grid(data=val,data.1=val)
library(plyr)
library(re
3 matches
Mail list logo