[R] Count of entries in a row of a data frame

Thomas Jensen thomas.jensen at eup.gess.ethz.ch
Thu Mar 18 23:28:24 CET 2010


Dear R-list,


I have data in the following format:

	Country 1 	Country 2	 Country 3 ...
1	0		1		 0	
2	1		0		 2
3	0		1		 0

Now I would like to create a variable that counts every non-zero element
of the rows, so for the above example it would be:

	Count
1	1
2	2
3	1

Any help from is greatly appreciated!

With kind regards
Thomas



More information about the R-help mailing list