简体   繁体   English

在data.frame中不包含0个元素的子集行

[英]Subset rows containing not 0 elements in a data.frame

I have a data.frame that looks like this: 我有一个看起来像这样的data.frame:

  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. 我想仅对不包含0个元素的行和列进行子集化。 The desired output will be: 所需的输出将是:

  cln1 cln2 cln3 cln4 3 9 7 12 4 98 23 11 

Assuming your data.frame is called "mydf": 假设您的data.frame被称为“mydf”:

> mydf[!rowSums(mydf == 0), ]
  cln1 cln2 cln3 cln4
2    3    9    7   12
4    4   98   23   11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM