set.seed(0xabcd)
 st = rnorm(20)
 names(st) = paste("gene", 1:20)
 a = matrix(sample(c(FALSE, TRUE), 60, replace=TRUE), nrow=3,
        dimnames = list(paste("category", LETTERS[1:3]), names(st)))
 applyByCategory(st, a, median)
Run the code above in your browser using DataLab