Skip to content

Instantly share code, notes, and snippets.

@jfaganUK
Created June 12, 2018 21:20
Show Gist options
  • Save jfaganUK/5be9f37476162d49cfa4e27e9f130595 to your computer and use it in GitHub Desktop.
Save jfaganUK/5be9f37476162d49cfa4e27e9f130595 to your computer and use it in GitHub Desktop.
reduce.tdm <- function(m, rs = 1, cs = 100) {
repeat {
i <- sum(dim(m))
cat("Min row sum\t", min(rowSums(m)),"\tMin col sum\t",min(colSums(m)), "\n")
m <- m[rowSums(m) >= rs, colSums(m) >= cs]
if(sum(dim(m)) == i) break
}
return(m)
}
m <- reduce.tdm(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment