Suppose I have a dataset that has 100-odd columns and I need to keep only those rows in the data which meets one condition applied across all 100 columns.. How do I do this?
Suppose, its like below... I need to only keep rows where either of Col1 or 2 or 3 or 4 is >0
Col1 Col2 Col3 Col4
1 1 3 4
0 0 4 2
4 3 4 3
2 1 0 2
1 2 0 3
0 0 0 0
In above example, except last row all rows will make it .. I need to place results in same dataframe as original. not sure if I can use the lapply to loop through the columns where>0 or I can use subset.. Any help is appreciated
Can I use column indices and do df<-subset(df,c(2:100)>0)
. This doesn't give me the right result.