Skip to content
Prev 297632 / 398498 Next

how to convert a vector to an upper matrix

ozzi wrote
My mistake.

mkupper <- function(A) {
    n <- length(A)
    m <- (1+sqrt(1+8*n))/2
    stopifnot(m==as.integer(m))
    print(m)
    L <- matrix(0,nrow=m,ncol=m)
    L[lower.tri(L)] <- A

    U <- t(L)
    U
}

A <- 1:6
mkupper(A)


--
View this message in context: http://r.789695.n4.nabble.com/how-to-convert-a-vector-to-an-upper-matrix-tp3587715p4633630.html
Sent from the R help mailing list archive at Nabble.com.