[R] table over a matrix dimension...

2014-07-10 Thread Jonathan Greenberg
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 is an easier way to accomplish this task: # Create a matrix of factors

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

2014-07-10 Thread Marc Schwartz
On Jul 10, 2014, at 12:03 PM, Jonathan Greenberg j...@illinois.edu 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

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 -