У меня есть некоторые данные, и я пытаюсь удалить из них значения NA.
Я применяю следующее:
data %>%
head(20) %>%
drop_na(contains("gvkey"))
, который удаляет все строки. Я хочу сохранить строки 12 и 16, поскольку эти две строки имеют значения в одном из столбцов gvkey[X]
. Если бы в gvkey2
была вейл, я бы тоже хотел сохранить эти строки. То же самое относится к gvkey[1]...[5]
.
Данные:
data <- structure(list(cod = structure(c(12L, 2L, 3L, 3L, 3L, 2L, 2L,
3L, 3L, 3L, 2L, 3L, 2L, 2L, 3L, 3L, 2L, 5L, 5L, 2L), .Label = c("01 Unassigned",
"02 US corporation", "03 Foreign corp, incl. state-owned", "04 US individual",
"05 Foreign individual", "06 US government", "07 Foreign government",
"08 US local government", "09 US state government", "US university",
"Foreign university", "US institute", "Foreign institute", "US hospital/med inst",
"Foreign hospital/med inst"), class = "factor"), cod_fix = c(32L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L), pdpass = c(12832332L, 11624193L, 12549858L, 11170486L,
10513915L, 13143949L, 10817896L, 12517845L, 13028479L, 12986393L,
11719402L, 12298245L, 12249804L, 12898008L, 13100249L, 12298245L,
10256638L, -19842L, -19842L, 11485267L), standard_name = c("& AEROSPACE FOUND",
"& COMMUNICATIONS", "& DESIGN LTD", "& FR", "& SA FAB DEBAUCHES",
"& SON INC", "& YET INC", "&&T TECH CO LTD", "01 COMMUNIQUE LAB INC",
"01 DB METRAVIB", "02 MICRO INC", "02 MICRO INT LTD", "02 TECH INC",
"02IC INC", "02MICRO", "02MICRO INT LTD", "03 CO", "080 STUDIO INC",
"0KAMOTO ; SHOSUKE", "1"), uspto_assignee = c(835951L, 721167L,
806186L, 182855L, 182585L, NA, 30140L, 802588L, NA, NA, 729315L,
782400L, 775728L, 825676L, NA, 782400L, 641605L, NA, NA, 708378L
), pdpco1 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 138961L,
NA, NA, NA, 138961L, NA, NA, NA, NA), source = c(NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, "m2006", NA, NA, NA, "m2006",
NA, NA, NA, NA), begyr1 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 2000L, NA, NA, NA, 2000L, NA, NA, NA, NA), gvkey1 = c(NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 138961L, NA, NA, NA,
138961L, NA, NA, NA, NA), endyr1 = c(NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, 2006L, NA, NA, NA, 2006L, NA, NA, NA, NA),
pdpco2 = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_), begyr2 = c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_), gvkey2 = c(NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), endyr2 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), pdpco3 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), begyr3 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), gvkey3 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), endyr3 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), pdpco4 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), begyr4 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), gvkey4 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), endyr4 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), pdpco5 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), begyr5 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), gvkey5 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), endyr5 = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_)), row.names = c(NA,
20L), class = "data.frame")