Created
March 5, 2015 07:21
-
-
Save gokceneraslan/3fb034307f07983d5121 to your computer and use it in GitHub Desktop.
Bin signal in a given matrix
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
bin.signal <- function(data, bin.width) { | |
if (is.matrix(data)) data <- list(data) | |
lapply(data, function(d) { | |
window.size <- ncol(d) | |
res <- t(apply(d, 1, function(row) { | |
sapply(seq(1, window.size, bin.width), function(s) sum(row[s:(s+bin.width-1)])) | |
})) | |
colnames(res) <- paste0('bin', seq_len(ncol(res))) | |
res | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment