Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. row.names 1 2 3 ... row.names 1 2 3 ....
  2.  
  3. A 0.1 0.2 0.3 A 1 1 1
  4. B 0.4 0.9 0.3 B 2 3 1
  5. C 0.9 0.9 0.4 C 1 3 1
  6. .
  7.  
  8. X S CONF P
  9. 1 A 0.1 1
  10. 1 B 0.4 2
  11. 1 C 0.9 1
  12. 2 A 0.2 1
  13. 2 B ......
  14.  
  15. out <- data.frame(X = rep(colnames(conf), each = nrow(conf)),
  16. S = rep(rownames(conf), ncol(conf)),
  17. CONF = c(conf), P = c(P))
  18. out
  19. # X S CONF P
  20. # 1 1 A 0.1 1
  21. # 2 1 B 0.2 1
  22. # 3 1 C 0.3 1
  23. # 4 2 A 0.4 2
  24. # 5 2 B 0.9 3
  25. # 6 2 C 0.3 1
  26. # 7 3 A 0.9 1
  27. # 8 3 B 0.9 3
  28. # 9 3 C 0.4 1
  29.  
  30. cbind.data.frame(X = rep(colnames(conf), each=nrow(conf)),
  31. S = rep(rownames(conf), times=nrow(conf)),
  32. CONF = matrix(t(conf), ncol=1),
  33. P = matrix(t(P), ncol=1))
  34.  
  35. conf <- matrix(
  36. c(0.1, 0.4, 0.9,
  37. 0.2, 0.9, 0.9,
  38. 0.3, 0.3, 0.4),
  39. ncol=3, byrow=T
  40. )
  41. rownames(conf) <- c("A", "B", "C")
  42. colnames(conf) <- 1:3
  43.  
  44. P <- matrix(
  45. c(1, 2, 1,
  46. 1, 3, 3,
  47. 1, 1, 1),
  48. ncol=3, byrow=T
  49. )
  50. rownames(P) <- c("A", "B", "C")
  51. colnames(P) <- 1:3
  52.  
  53. library(reshape)
  54. conf <- cbind(as.data.frame(conf), "S"=rownames(conf))
  55. P <- cbind(as.data.frame(P), "S"=rownames(P))
  56. out <- merge(melt(conf, id="S"), melt(P, id="S"), by=c("variable", "S"))
  57. colnames(out) <- c("X", "S", "CONF", "P")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement