I have a table like this,
gene1 a 2 0 1 0
gene2 b 5 0 2 2
gene3 a 7 4 0 0
I want to count the number of non-zero elements in rows and columns and append it to the same table. This is how I did it for rows: myfile$rowsum <- rowSums(myfile[4:6] != 0). For columns I am trying to make this one work, but it starts from the 1st column and not the 4th: rbind(myfile, colSums(myfile != 0)) Not sure how to append it and how to move starting from column 4. So i want something like this
gene1 a 2 0 1 0 1
gene2 b 5 0 2 2 2
gene3 a 7 4 0 0 1
1 2 1
This is working, thanks!