Skip to content

Instantly share code, notes, and snippets.

@gokceneraslan
Created March 5, 2015 07:21
Show Gist options
  • Save gokceneraslan/3fb034307f07983d5121 to your computer and use it in GitHub Desktop.
Save gokceneraslan/3fb034307f07983d5121 to your computer and use it in GitHub Desktop.
Bin signal in a given matrix
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