Very new to R and I have a .rda file that contains a matrix of gene IDs and counts for each ID in 96 columns. It looks like this:
Another method using plyr's numcolwise:
plyr
numcolwise
library(plyr) dat <- data.frame(a = sample(1:25, 25), b = rep(0, 25), c = sample(1:25, 25)) nonzero <- function(x) sum(x != 0) numcolwise(nonzero)(dat) a b c 1 25 0 25