Мы можем обернуть с na.omit
, а затем distinct
library(dplyr)
df1 %>%
filter(!is.na(CONSENSUSMAP)) %>%
distinct(SVEVOMAP, .keep_all = TRUE)
# CLONEID CONSENSUSMAP SVEVOMAP
#1 2277607 1A chr1A
#2 1126457 7B chr7B
Или, если он основан на подстроке, тогда
library(stringr)
df1 %>%
filter(!is.na(CONSENSUSMAP), CONSENSUSMAP == str_sub(SVEVOMAP, 4, 5))
# CLONEID CONSENSUSMAP SVEVOMAP
#1 2277607 1A chr1A
#2 1126457 7B chr7B
Или с str_remove
df1 %>%
filter(!is.na(CONSENSUSMAP), CONSENSUSMAP == str_remove(SVEVOMAP, 'chr'))
данные
df1 <- structure(list(CLONEID = c("1228104", "2277691", "2277607", "1e+08",
"1229677", "1126457"), CONSENSUSMAP = c(NA, NA, "1A", NA, "1B",
"7B"), SVEVOMAP = c("chr1A", "chr1A", "chr1A", "chr1A", "chr1A",
"chr7B")), row.names = c(NA, -6L), class = "data.frame")