Re: [R] table over a matrix dimension...

2014-07-10 Thread William Dunlap
You can make make a factor with a common set of levels out of each slice of the matrix so all the tables are the same size: f <- function (charMatrix, levels = unique(sort(as.vector(charMatrix { apply(charMatrix, 1, function(x) table(factor(x, levels = levels))) } used as > m <- cbind(c("A

Re: [R] table over a matrix dimension...

2014-07-10 Thread Marc Schwartz
On Jul 10, 2014, at 12:03 PM, Jonathan Greenberg wrote: > R-helpers: > > I'm trying to determine the frequency of characters for a matrix > applied to a single dimension, and generate a matrix as an output. > I've come up with a solution, but it appears inelegant -- I was > wondering if there i