Last active
August 22, 2023 20:11
-
-
Save philipp-baumann/06db0747ba2d260a02e5f246107d0579 to your computer and use it in GitHub Desktop.
snv-benchmark.R
This file contains 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
snv_impl_base <- function(X) { | |
X <- as.matrix(X) | |
X <- sweep(X, 1L, rowMeans(X, na.rm = TRUE), `-`) | |
X_sc <- sweep(X, 1L, apply(X, 1L, sd, na.rm = TRUE), `/`) | |
return(X_sc) | |
} | |
snv_impl_base_mstats <- function(X) { | |
X <- as.matrix(X) | |
X <- sweep(X, 1L, matrixStats::rowMeans2(X, na.rm = TRUE), `-`) | |
X_sc <- sweep(X, 1L, matrixStats::rowSds(X, na.rm = TRUE), "/") | |
return(X_sc) | |
} | |
snv_impl_dt <- function(X) { | |
X[, colnames(X) := | |
lapply(.SD, function(x) x - rowMeans(as.matrix(x), na.rm = TRUE)), | |
.SDcols = colnames(X) | |
] | |
X[, colnames(X) := | |
lapply(.SD, function(x) x - sd(x, na.rm = TRUE)), | |
.SDcols = colnames(X) | |
] | |
X <- as.matrix(X) | |
return(X) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment