Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. library(Matrix)
  2. dat = data.frame(t(replicate(5,
  3. sample(as.character(1:3),100,replace=T))))
  4. tmp_m = combn(1:nrow(dat), 2)
  5. m = matrix(NA, nrow(dat), nrow(dat))
  6. m[t(tmp_m)] = rowSums(dat[tmp_m[1,],] == dat[tmp_m[2,],])
  7. m[lower.tri(m)] = m[upper.tri(m)]
  8. apply(out, 2, function(x) match(1:2, order(x)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement