Re: [R] Summarizing each row into a frequency table

2009-03-24 Thread William Dunlap
o.com ---- [R] Summarizing each row into a frequency table Daren Tan darentan76 at gmail.com Tue Mar 24 01:46:21 CET 2009 I have a matrix containing -1, 0, 1, however certain rows will not have all 3 numbers. I have written some codes to compute the frequency table of how

Re: [R] Summarizing each row into a frequency table

2009-03-23 Thread Gabor Grothendieck
Try this (haven't checked the speed): f <- function(x) table(factor(x, c(-1, 0, 1))) 100 * prop.table(t(apply(m, 1, f)), 1) On Mon, Mar 23, 2009 at 8:46 PM, Daren Tan wrote: > I have a matrix containing -1, 0, 1, however certain rows will not > have all 3 numbers. I have written some codes to c

Re: [R] Summarizing each row into a frequency table

2009-03-23 Thread Peter Alspach
Of Daren Tan > Sent: Tuesday, 24 March 2009 1:46 p.m. > To: r-help@r-project.org > Subject: [R] Summarizing each row into a frequency table > > I have a matrix containing -1, 0, 1, however certain rows > will not have all 3 numbers. I have written some codes to > compute t

[R] Summarizing each row into a frequency table

2009-03-23 Thread Daren Tan
I have a matrix containing -1, 0, 1, however certain rows will not have all 3 numbers. I have written some codes to compute the frequency table of how many -1s, 0s, 1s per row, but it is very ugly and not efficient if there are more than 3 numbers. Please suggest. m <- rbind(sample(0:1, replace=T,