Skip to content

Instantly share code, notes, and snippets.

@philipp-baumann
Last active August 22, 2023 20:11
Show Gist options
  • Save philipp-baumann/06db0747ba2d260a02e5f246107d0579 to your computer and use it in GitHub Desktop.
Save philipp-baumann/06db0747ba2d260a02e5f246107d0579 to your computer and use it in GitHub Desktop.
snv-benchmark.R
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