Опция с использованием tidyverse
library(tidyverse)
df1 %>%
filter(Genes == "A2M") %>%
select_if(~is.numeric(.x) & .x != 0) %>%
names %>%
select(df1, .)
# Sample2 Sample3
#1 59 11
#2 7708 7306
#3 71 1317
#4 0 1195
#5 1233 0
data
df1 <- structure(list(Genes = c("A1BG", "A2M", "A2ML1", "A4GALT", "AAAS"
), Sample1 = c(14L, 0L, 64L, 142L, 1821L), Sample2 = c(59L, 7708L,
71L, 0L, 1233L), Sample3 = c(11L, 7306L, 1317L, 1195L, 0L), Sample4 = c(31L,
0L, 3406L, 700L, 959L)), class = "data.frame", row.names = c(NA,
-5L))