Skip to content

Instantly share code, notes, and snippets.

@eschen42
Created November 30, 2018 15:20
Show Gist options
  • Select an option

  • Save eschen42/915e09f7f3f42de02040a21e7785bf80 to your computer and use it in GitHub Desktop.

Select an option

Save eschen42/915e09f7f3f42de02040a21e7785bf80 to your computer and use it in GitHub Desktop.
R - Center a matrix on its column means
# center with 'colMeans()' - ref: http://gastonsanchez.com/visually-enforced/how-to/2014/01/15/Center-data-in-R/
center_colmeans <- function(x) {
xcenter <- colMeans(x)
x - rep(xcenter, rep.int(nrow(x), ncol(x)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment