I've had a look through the existing subset Q&A's on this site and couldn't quite find what I was looking for.
I want to subset a data frame based on one condition (e.g. if the value is below 5). However, I only want the rows where the value in all of the columns is below 5.
For example using the iris
dataset - I would like to select all the rows where columns 1-3 all have values below 5.
subdata <- iris[which(iris[,1:3]<5),]
This doesn't do it for me. I get lots of NA rows at the bottom of the subset data.
Any help much appreciated!
Try
subdata <- iris[apply(iris[,1:3] < 5, 1, all),]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With