У меня есть мой фрейм данных, который выглядит следующим образом:
df <- structure(list(V1 = c(30L, 30L, 32L, 48L, 42L, 29L, 36L, 28L,
53L, 49L, 25L), V2 = structure(c(5L, 5L, 1L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 1L), .Label = c(" ?", " Federal-gov", " Local-gov",
" Never-worked", " Private", " Self-emp-inc", " Self-emp-not-inc",
" State-gov", " Without-pay"), class = "factor"), V3 = c(188146L,
59496L, 293936L, 149640L, 116632L, 105598L, 155537L, 183175L,
169846L, 191681L, 200681L), V4 = structure(c(12L, 10L, 6L, 12L,
11L, 16L, 12L, 16L, 12L, 16L, 16L), .Label = c(" 10th", " 11th",
" 12th", " 1st-4th", " 5th-6th", " 7th-8th", " 9th", " Assoc-acdm",
" Assoc-voc", " Bachelors", " Doctorate", " HS-grad", " Masters",
" Preschool", " Prof-school", " Some-college"), class = "factor"),
V5 = c(9L, 13L, 4L, 9L, 16L, 10L, 9L, 10L, 9L, 10L, 10L),
V6 = structure(c(3L, 3L, 4L, 3L, 3L, 1L, 3L, 1L, 3L, 3L,
5L), .Label = c(" Divorced", " Married-AF-spouse", " Married-civ-spouse",
" Married-spouse-absent", " Never-married", " Separated",
" Widowed"), class = "factor"), V7 = structure(c(8L, 13L,
1L, 15L, 11L, 14L, 4L, 2L, 2L, 5L, 1L), .Label = c(" ?",
" Adm-clerical", " Armed-Forces", " Craft-repair", " Exec-managerial",
" Farming-fishing", " Handlers-cleaners", " Machine-op-inspct",
" Other-service", " Priv-house-serv", " Prof-specialty",
" Protective-serv", " Sales", " Tech-support", " Transport-moving"
), class = "factor"), V8 = structure(c(1L, 1L, 2L, 1L, 1L,
2L, 1L, 2L, 6L, 1L, 4L), .Label = c(" Husband", " Not-in-family",
" Other-relative", " Own-child", " Unmarried", " Wife"), class = "factor"),
V9 = structure(c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L), .Label = c(" Amer-Indian-Eskimo", " Asian-Pac-Islander",
" Black", " Other", " White"), class = "factor"), V10 = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c(" Female",
" Male"), class = "factor"), V11 = c(5013L, 2407L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L), V12 = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L), V13 = c(40L, 40L, 40L, 40L, 45L,
58L, 40L, 40L, 40L, 50L, 40L), V14 = structure(c(40L, 40L,
1L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L), .Label = c(" ?",
" Cambodia", " Canada", " China", " Columbia", " Cuba", " Dominican-Republic",
" Ecuador", " El-Salvador", " England", " France", " Germany",
" Greece", " Guatemala", " Haiti", " Holand-Netherlands",
" Honduras", " Hong", " Hungary", " India", " Iran", " Ireland",
" Italy", " Jamaica", " Japan", " Laos", " Mexico", " Nicaragua",
" Outlying-US(Guam-USVI-etc)", " Peru", " Philippines", " Poland",
" Portugal", " Puerto-Rico", " Scotland", " South", " Taiwan",
" Thailand", " Trinadad&Tobago", " United-States", " Vietnam",
" Yugoslavia"), class = "factor"), V15 = structure(c(1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L), .Label = c(" <=50K",
" >50K"), class = "factor")), row.names = 60:70, class = "data.frame")
Я хочу избавиться от строк, которые имеют \\?
. Я попробовал этот код ниже, но я не получаю то, что мне нужно от этого. Может кто-нибудь помочь мне?
new_mtx <- apply (df, 1, function(x) any(!grepl("\\?", x)) )
df[new_mtx,]