Reputation: 905
I have a data.frame that looks like this:
cln1 cln2 cln3 cln4 0 1 2 0 3 9 7 12 1 0 13 0 4 98 23 11
I would like to subset only that rows and columns not containing 0 elements. The desired output will be:
cln1 cln2 cln3 cln4 3 9 7 12 4 98 23 11
Upvotes: 1
Views: 1123
Reputation: 193687
Assuming your data.frame
is called "mydf":
> mydf[!rowSums(mydf == 0), ]
cln1 cln2 cln3 cln4
2 3 9 7 12
4 4 98 23 11
Upvotes: 4