I’m trying to implement a function which takes a dynamic subset based on a list of column names of any length
The static code is:
s <- c("s0","s1","s2")
d.subset <- d[ d$s0 > 0 | d$s1 > 0 | d$s2 > 0,]
However, I want to generate the d$s0 > 0 | d$s1 > 0 | d$s2 > 0 part based on s. I tried as.formula() for generating it, but it gave me an “invalid formula” error.
An example data frame:
Here is an easy solution with
rowSums:The result: