I've a data frame which have many columns with common prefix "_B" e,g '_B1', '_B2',...'_Bn'. So that I can grab the column names by:
allB <- c(grep( "_B" , names( my.df ),value = TRUE ) )
I wish to select the rows for which each of these _B* columns passes a single condition like values >= some_cutoff
Can someone tell how to do that, my efforts with 'all()' and 'any()' failed
set.seed(12345)
my.df <- data.frame(a = round(rnorm(10,5),1), m_b1= round(rnorm(10,4),1),m_b2=round(rnorm(10,4),1))
allB <- c(grep( "_b" , names( my.df ),value = TRUE ) )
> my.df
a m_b1 m_b2
1 5.6 3.9 4.8
2 5.7 5.8 5.5
3 4.9 4.4 3.4
4 4.5 4.5 2.4
5 5.6 3.2 2.4
6 3.2 4.8 5.8
7 5.6 3.1 3.5
8 4.7 3.7 4.6
9 4.7 5.1 4.6
10 4.1 4.3 3.8
I wish to select rows for which every m_b1 and m_b2 column is >= 4.0
library(dplyr);my.df %>% filter_at(allB, all_vars(. >= cutoff))Please provide a small reproducible example with expected output