How to add a column giving the number of values >0 in each row to a table in R?

后端 未结 2 1052
广开言路
广开言路 2021-01-25 02:52

I have a table containing data that looks somewhat like this:

treatment, species1, species2, ... 
A, 3, 4, ... 
B, 2, 5, ...

I want to calculat

2条回答
  •  难免孤独
    2021-01-25 03:15

    Depending on how your table is stored (this should work directly if it is the result of table, but could need some tweaking if it is a data frame or other structure), but it could be as simple as:

    newtable <- addmargins(mytable, 1, FUN = function(x) sum( x > 0 ) )
    

提交回复
热议问题