[R] frequency count by row

mari681 marianna.bolognesi at gmail.com
Tue Mar 6 18:03:49 CET 2012

I feel this is a very easy thing but I've never done it before and it is
getting frustrating.
I have a big data.frame (1445846 rows,  15 col)
 that looks like this:

                V1          V2         V3          V4          V5

1    home      sister        brother   chair       0
2    cat             dog          animal      0           0
3    girl            boy           0                0           0
4    knife      fork          spoon          0            0

and I want to count how many values different from 0 are in each row, and
get the output count in a vector that is as long as length(MyTable). For the
above example it would be c (4,3,2,3).
I've tried   sum (MyTable != "0") but it gives the total amount of values
different from 0 in all the data.frame.
And sum(MyTable [1,] != "0") obviously gives only the first row, even if I
repeat it throughout all length(MyTable).
How does that work?

Thank you,

a newbie.

View this message in context: http://r.789695.n4.nabble.com/frequency-count-by-row-tp4450553p4450553.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list