I have a dataframe like so: df
ID Black red blue green
1 0 1 1 1
2 0 0 2 1
3 0 5 1 2
4 0 0 1 2
5 0 0 1 2
with this data, how can I count the columns that have any number regardless of the actual number? Is there any way to do this?
I tried rowSums(df)
but result is not what I want.
My desired output is:
ID Black red blue green count
1 0 1 1 1 3
2 0 0 2 1 2
3 0 5 1 2 3
4 0 0 1 2 2
5 0 0 1 2 2
thanks in advance!