Один из вариантов: filter_at
library(dplyr)
df %>%
filter_at(11:20, any_vars( . != 0))
Воспроизводимый пример
df1 %>%
filter_at(vars(`11`:`13`), any_vars(. != 0))
# A tibble: 2 x 4
# `11` `12` `13` grp
# <dbl> <dbl> <dbl> <chr>
#1 1 0 4 a
#2 0 1 0 b
Или использование across
из devel
версии dplyr
df1 %>%
filter(across(cols = matches('^\\d+$'), ~ (.x == 0))) %>%
anti_join(df1, .)
# A tibble: 2 x 4
# `11` `12` `13` grp
# <dbl> <dbl> <dbl> <chr>
#1 1 0 4 a
#2 0 1 0 b
Обновление
На основании обновления ОП, если у нас есть 'n' в качестве индекса некоторого столбца и мы хотим фильтровать по столбцам с этой позиции до 100 столбцов после этого
n <- 5
df %>%
filter_at(n:(n+100), any_vars(. != 0))
Обновление2
df2 %>%
filter_at(vars(F, G, H), any_vars(. != 0))
# A tibble: 2 x 10
# A B C D E F G H I J
# <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
#1 1 1 1 1 1 1 1 0 1 1
#2 0 0 0 0 0 0 0 1 0 0
Или с использованием base R
df2[rowSums(df2[c("F", "G", "H")] != 0) > 0,]
data
df1 <- tibble(`11` = c(1, 0, 0), `12` = c(0, 1, 0), `13` = c(4, 0, 0),
grp = letters[1:3])
df2 <- structure(list(A = c(1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L),
B = c(1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L), C = c(1L,
0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L), D = c(1L, 0L, 1L, 0L,
1L, 1L, 0L, 0L, 0L, 0L), E = c(1L, 0L, 1L, 0L, 1L, 1L, 0L,
0L, 1L, 0L), F = c(0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L
), G = c(0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L), H = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L), I = c(0L, 0L, 1L, 0L,
1L, 0L, 0L, 0L, 0L, 0L), J = c(0L, 0L, 1L, 0L, 1L, 0L, 0L,
0L, 0L, 0L)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))