ozzi wrote
> 
> Dear Berend,
> 
> the coding is not working for more than 6. Try to plug 10 or other number.
> Would you please correct ?
> 

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.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to