I am trying to extract meaningful rows in a data large data frame with 2k column and 1m rows in which many column have value equals to zero. Meaningful is defined as most columns are value other than zero.
As toy example
difference_from_mean <- data.frame('col1' = c(-1, 1.5, -1, 1.2, 1), 'col2' = c(1, -0.5, 0, -4, 0), 'col3' = c(0, 1, 0, 1, 0), 'col4' = c(0, 0, 2, 1, 0))
difference_from_mean
col1 col2 col3 col4
1 -1.0 1.0 0 0
2 1.5 -0.5 1 0
3 -1.0 0.0 0 2
4 1.2 -4.0 1 1
5 1.0 0.0 0 0
prefer to get the result
> difference_from_mean_filtered
col1 col2 col3 col4
1 -1.0 1.0 0 0
2 1.5 -0.5 1 0
3 -1.0 0.0 0 2
4 1.2 -4.0 1 1
I tried rowSums
but did not work as the value could be negative resulting zero or near zero to many raws. Above is just a toy example. I am looking to get the count of column with zero in to a new column and that would help in subsetting the df (tried the string match and it also did not work as it is counting 0 from the decimal).