This question already has an answer here:
I have a dataset with 70 columns.
I would like to subset entire rows of the dataset where a value in any column 5 through 70 is greater than the value 7.
I have tried the following code, however, I do not want TRUE/FALSE values. I would just like the rows that do not meet the criteria eliminated from the data frame
subset <- (data[, 5:70] > 7)
You can use a combination of
apply
withMARGIN = 1
andany
.Reproducible example:
Or in your case
It's better (faster) to use direct
[
indexing instead ofsubset
, see e.g. Faster way to subset on rows of a data frame in R?say this is your data:
you can use the
subset
command to extract what you want:We can use
rowSums
Or with
subset
We can also use
filter_at
fromdplyr
withany_vars
Using reproducible data from
mtcars
(stealing idea from @Maurits Evers)Using
filter_at
also gives the same output