Created
November 30, 2018 15:20
-
-
Save eschen42/915e09f7f3f42de02040a21e7785bf80 to your computer and use it in GitHub Desktop.
R - Center a matrix on its column means
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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