Skip to content
Prev 273071 / 398506 Next

Covariance-Variance Matrix and For Loops

Surprising: must be  newer update than I realized....anyways, here's
the code if you want to add it manually:

simplify2array <-
function (x, higher = TRUE)
{
    if (length(common.len <- unique(unlist(lapply(x, length)))) >
        1L)
        return(x)
    if (common.len == 1L)
        unlist(x, recursive = FALSE)
    else if (common.len > 1L) {
        n <- length(x)
        r <- as.vector(unlist(x, recursive = FALSE))
        if (higher && length(c.dim <- unique(lapply(x, dim))) ==
            1 && is.numeric(c.dim <- c.dim[[1L]]) && prod(d <- c(c.dim,
            n)) == length(r)) {
            iN1 <- is.null(n1 <- dimnames(x[[1L]]))
            n2 <- names(x)
            dnam <- if (!(iN1 && is.null(n2)))
                c(if (iN1) rep.int(list(n1), length(c.dim)) else n1,
                  list(n2))
            array(r, dim = d, dimnames = dnam)
        }
        else if (prod(d <- c(common.len, n)) == length(r))
            array(r, dim = d, dimnames = if (!(is.null(n1 <- names(x[[1L]])) &
                is.null(n2 <- names(x))))
                list(n1, n2))
        else x
    }
    else x
}
<environment: namespace:base>
On Sat, Oct 1, 2011 at 4:22 AM, sf1979 <simonfuller9 at gmail.com> wrote: