Referencing a range of columns in dplyr
We can get the indexes first and then use rowSums
,
v1 <- which(names(df) == 'A2') #find first column
#[1] 3
v2 <- which(names(df) == 'B1') #find last column
#[1] 4
df[rowSums(df[v1:v2])>10,]
# txt A1 A2 B1 B2
#1 ala 6 9 12 23
I think the most dplyr
-esque way would be:
df %>%
filter(rowSums(select_(., 'A2:B1')) > 10)
Which gives:
# txt A1 A2 B1 B2
#1 ala 6 9 12 23