R/aggmean.R

Defines functions aggmean

Documented in aggmean

aggmean <- function(X, y = NULL) {
    
    ## Works also if y is a factor
    
    X <- .mat(X)
    zdim <- dim(X)
    n <- zdim[1]
    p <- zdim[2]
    colnam <- colnames(X)
    
    if(is.null(y)) 
        y <- rep(1, n)

    lev <-  sort(unique(y))
    nlev <- length(lev)
    ni <- c(table(y))
    
    ct <- matrix(nrow = nlev, ncol = p)
    for(i in seq_len(nlev))
        ct[i, ] <- colMeans(X[y == lev[i], , drop = FALSE])
    dimnames(ct) <- list(lev, colnam)

    list(ct = ct, lev = lev, ni = ni)
    
    }

Try the rchemo package in your browser

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

rchemo documentation built on Sept. 11, 2024, 8:05 p.m.