R/colSubset.R

Defines functions colSubset

Documented in colSubset

## -*- truncate-lines: t; -*-

colSubset <- function(x) {

    nr <- dim(x)[1L]
    nc <- dim(x)[2L]
    QR <- qr(x, LAPACK = FALSE)

    if ((qrank <- QR$rank) == nc) {
        list(columns = seq_len(nc),
             multiplier = diag(nc))
    } else {
        cols  <- QR$pivot[seq_len(qrank)]
        cols_ <- QR$pivot[(qrank + 1L):nc]
        D <- array(0, dim = c(qrank, nc))
        D[cbind(seq_along(cols), cols)] <- 1
        D[ ,cols_] <- qr.solve(x[ ,cols], x[ ,cols_])
        list(columns = cols,
             multiplier = D)
    }
}

Try the NMOF package in your browser

Any scripts or data that you put into this service are public.

NMOF documentation built on Oct. 20, 2023, 9:07 a.m.