How to remove rows with 0 values using R

Solution 1:

df[apply(df[,-1], 1, function(x) !all(x==0)),]

Solution 2:

A lot of options to do this within the tidyverse have been posted here: How to remove rows where all columns are zero using dplyr pipe

my preferred option is using rowwise()

library(tidyverse)

df <- df %>% 
    rowwise() %>% 
    filter(sum(c(col1,col2,col3)) != 0)