Skip to content
Prev 140659 / 398506 Next

Alignment and Reshaping of the matrix

try this:

mat <- data.matrix(read.table(
textConnection("85 .90 86 .89 87 .98 86 .87
  88 .98 90 .78 88 .76 89 .56
  90 .67 95 .67 89 .89 90 .87
  91 .56 96 .87 90 .76 92 .98")))
closeAllConnections()

nc <- ncol(mat)
labs <- mat[, seq(1, nc, 2)]
vals <- mat[, -seq(1, nc, 2)]
lis <- split(c(vals, col(vals)), c(labs, labs))
t(sapply(lis, function(x, out){
     nx <- length(x)
     ind <- seq(1, nx/2)
     out[x[-ind]] <- x[ind]
     out
}, out = numeric(nc/2)))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
      http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting dinesh kumar <barupal at gmail.com>:
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm