I have a dataframe with 0 and 1 values like this:
stock1,stock2,stock3,stock4
1,0,0,0
1,0,1,0
0,0,1,0
1,0,1,0
I would like to remove the rows which all their rows have 0 values, in the previous example they are stoc2 and stock4 columns. In order to make it I calculate the sum and have a need row
stock1,stock2,stock3,stock4
1,0,0,0
1,0,1,0
0,0,1,0
1,0,1,0
3,0,3,0
Using something like this:
for (i in 1:ncol(df)){
col_number <- paste("df$stock",i)
col_number <- NULL # I could find a way to have the df column and not the variable
}
It is a little frustrated way. Any idea if there is a more optimal way to make it?