R/mycenter.R

Defines functions mycenter

Documented in mycenter

#' Subtract column means from columns of a matrix
#'
#'  Subtract the mean from the columns.
#'
#'  This utility function subtracts the mean from each of the columns.
#'
#' @param X a data matrix
#'
#' @return a centered matrix.
#'
#'
mycenter = function(X){
    X_centered = matrix(NaN, dim(X)[1], dim(X)[2])
    meanvec = mymeanvector(X)
    for(k in 1:dim(X)[2]){
        X_centered[,k] = X[,k] - meanvec[k]
    }
    return(X_centered)
}
jeffniv/Lab1Intro documentation built on Jan. 24, 2020, 1:26 a.m.