R - I want to go through rows of a big matrix and remove all zeros

后端 未结 5 1101
星月不相逢
星月不相逢 2021-01-07 10:55

I have a lot of rows and columns in a very large matrix (184 x 4000, type double), and I want to remove all 0\'s. The values in the matrix are usually greater than 0 but the

5条回答
  •  情深已故
    2021-01-07 11:32

    This worked for me, slightly change of @Richard Scriven:

    remove_zeros<- function(x)
    {
      x = x[!apply(x == 0, 1, all),]
      return(x)
    }
    

提交回复
热议问题