Drop rows with all missing (NA
) values.
Details
Drop rows that have no observed values, i.e., all values in the row are
missing (NA
), excluding the ignored columns.
See also
Other dataManipulation:
columnBindFill()
,
convert.magic()
,
dropColsWithAllNA()
,
varsDifferentTypes()
Other dataEvaluations:
dropColsWithAllNA()
,
is.nan.data.frame()
,
not_all_na()
,
not_any_na()
Examples
# Prepare Data
df <- expand.grid(ID = 1:100, time = c(1, 2, 3))
df <- df[order(df$ID),]
row.names(df) <- NULL
df$score1 <- rnorm(nrow(df))
df$score2 <- rnorm(nrow(df))
df$score3 <- rnorm(nrow(df))
df[sample(1:nrow(df), size = 100), c("score1","score2","score3")] <- NA
# Drop Rows with All NA in Non-Ignored Columns
dropRowsWithAllNA(df, ignore = c("ID","time"))
#> ID time score1 score2 score3
#> 1 1 1 1.467485607 -0.67987338 0.510471244
#> 3 1 3 0.359622515 1.77247739 0.636432097
#> 4 2 1 1.837521669 0.27793329 -1.013955594
#> 7 3 1 0.293728600 0.53066370 0.436178180
#> 8 3 2 1.330807535 -1.12476618 -0.164089402
#> 10 4 1 0.944012124 -1.18796740 0.415432504
#> 11 4 2 -0.163110155 2.24883111 -0.048104283
#> 12 4 3 0.020936334 1.55316175 0.198292951
#> 15 5 3 -1.017904646 -0.24942787 -0.139421427
#> 16 6 1 -0.320525550 -2.17231912 -1.325197658
#> 18 6 3 -2.168675688 -0.98048575 1.357852830
#> 19 7 1 0.066409650 -1.79278068 -1.220784861
#> 22 8 1 0.196097401 0.80626313 -1.012275885
#> 23 8 2 -0.656023781 -0.68381307 -0.432531486
#> 24 8 3 -0.478355050 0.33438806 0.345706392
#> 25 9 1 0.568878744 0.94300642 0.190927596
#> 26 9 2 -2.102626810 -0.89838767 1.287488578
#> 28 10 1 0.416918015 0.09233868 0.593561305
#> 29 10 2 0.473867599 -0.35169603 -1.815799874
#> 30 10 3 -0.062925119 0.11537300 -0.460524573
#> 31 11 1 -1.636219349 -0.14326135 0.746337982
#> 35 12 2 0.467589309 -0.12614333 -0.003256871
#> 37 13 1 0.396813229 0.91043704 0.309380270
#> 40 14 1 -0.805206472 -0.17999302 0.070972006
#> 41 14 2 -1.932053070 0.97685639 -2.313759365
#> 43 15 1 1.792486559 -0.03409839 -0.352441451
#> 44 15 2 1.123194865 1.48873220 -1.533292787
#> 45 15 3 1.609947684 -0.18983930 -1.734069209
#> 46 16 1 1.732799496 -1.08930962 0.141892735
#> 47 16 2 1.275703717 0.37108948 -0.219599601
#> 48 16 3 0.424007988 -1.02777011 0.591564494
#> 50 17 2 -0.597937324 -0.52029856 -0.372564160
#> 51 17 3 -0.722073272 -0.05224443 0.264545865
#> 53 18 2 1.473362511 -0.32797907 -0.418319774
#> 54 18 3 -0.316206077 -1.28534762 -2.078760627
#> 56 19 2 -1.986179040 0.25747566 -0.705640744
#> 57 19 3 0.705734028 0.20131940 0.986688400
#> 59 20 2 0.758480158 0.50663659 -0.496043573
#> 62 21 2 0.075529822 0.04039804 0.028015821
#> 63 21 3 0.267751527 -0.20078138 0.526890091
#> 65 22 2 1.209748781 0.16665552 -0.587592446
#> 66 22 3 -1.253055561 -0.52428478 -0.430471444
#> 67 23 1 1.765028630 0.01756390 -0.022966263
#> 68 23 2 -0.159322027 0.94851719 0.074873923
#> 69 23 3 0.898874217 0.27026578 -2.089995616
#> 70 24 1 -0.704995332 -0.16094140 1.023897173
#> 71 24 2 1.126896570 1.96519951 0.623240132
#> 72 24 3 -1.974322214 0.39554804 -1.367330008
#> 73 25 1 -1.244772830 0.87371937 0.044589523
#> 75 25 3 0.579097050 -1.48522645 -0.178469697
#> 76 26 1 -1.037890010 -0.83616230 2.101677593
#> 77 26 2 1.561622325 -0.64626921 -0.242409658
#> 78 26 3 0.101959622 -0.04743704 0.011717215
#> 80 27 2 2.325851550 -0.09973867 0.274491395
#> 81 27 3 -1.293149956 0.08599646 -0.622731928
#> 84 28 3 0.480623395 -0.90680641 -0.392461437
#> 85 29 1 2.017342464 0.59115715 0.357845575
#> 87 29 3 0.656575520 0.07687238 0.066689713
#> 88 30 1 1.026297846 -0.06783720 0.257355650
#> 90 30 3 1.120615649 0.04909540 -0.730508027
#> 91 31 1 0.399897655 -0.03280005 -0.395841246
#> 92 31 2 -0.984527658 -0.51092478 -1.415808515
#> 93 31 3 -0.502562184 0.35643054 -0.108938918
#> 95 32 2 2.191481010 0.57920526 0.450190145
#> 96 32 3 -0.165042212 -1.47515865 0.387345818
#> 97 33 1 -0.686040800 1.32380523 -0.258295014
#> 101 34 2 -0.723484004 0.62121117 0.172922695
#> 102 34 3 1.390088740 1.80910855 0.426641536
#> 103 35 1 0.681840626 1.11398601 -0.813699585
#> 106 36 1 -0.800331265 0.25594028 0.390101788
#> 107 36 2 -0.488457510 -0.77721893 0.956724098
#> 108 36 3 0.539004516 -0.95031824 -0.169973563
#> 109 37 1 1.435171017 1.23051633 -0.379977916
#> 110 37 2 -0.261838719 -0.29032133 0.144207957
#> 111 37 3 -1.418623721 -1.24524959 -0.718284089
#> 112 38 1 -0.513792720 -0.92511062 0.206108648
#> 113 38 2 0.772301225 -0.35175827 -0.367334361
#> 114 38 3 1.403682339 -0.04163083 0.788442877
#> 115 39 1 -0.015804912 0.72929742 -0.310952795
#> 117 39 3 -2.116392160 3.58694548 1.085279663
#> 118 40 1 0.150371437 0.75574301 -0.784779324
#> 120 40 3 -0.905454844 0.82934571 -1.056691432
#> 121 41 1 -0.749986903 -0.30513624 -0.996890554
#> 122 41 2 -0.786576021 0.71010332 -0.672605085
#> 124 42 1 -1.390851305 0.35822370 2.236077683
#> 127 43 1 -0.967621014 0.57434653 -0.840974862
#> 129 43 3 -0.069089037 3.03758116 0.429372125
#> 130 44 1 -0.426188249 -1.59166713 0.811017521
#> 131 44 2 -2.251403727 -0.67368924 -0.174299949
#> 132 44 3 -0.914170952 0.72857280 -0.316371483
#> 133 45 1 -0.800524582 -1.15156224 -0.493001895
#> 135 45 3 0.660649173 -0.13207528 -1.103744984
#> 138 46 3 -0.781818406 1.16794898 -0.307474298
#> 140 47 2 1.015236070 -0.16311581 -1.710825390
#> 141 47 3 0.294676272 1.27526535 0.595309608
#> 143 48 2 -0.822289822 1.47436052 -0.085739756
#> 144 48 3 1.691546077 -1.51743472 0.032286550
#> 146 49 2 0.929693563 0.10746739 0.808938069
#> 148 50 1 0.617598091 0.44851998 -1.703857479
#> 149 50 2 -0.830615177 0.50807095 0.525504589
#> 150 50 3 -1.133375927 0.35021264 -0.803033850
#> 151 51 1 -0.156378319 0.75821367 -0.237655721
#> 152 51 2 -0.243091747 0.29092872 0.855349059
#> 153 51 3 -1.129264413 0.02285959 -0.469487045
#> 154 52 1 -0.062192485 -0.20814311 0.118012784
#> 155 52 2 0.487082631 -0.26361162 1.247441555
#> 156 52 3 -0.054636953 -1.98413580 -0.688397299
#> 158 53 2 -1.453375000 -0.45429735 -0.042932415
#> 160 54 1 -1.391001690 -0.28917939 -1.466993454
#> 161 54 2 -2.244235104 0.51190457 2.235778380
#> 163 55 1 -0.686551360 -0.22247479 -1.167913785
#> 164 55 2 -0.482915280 -1.45215149 0.149528831
#> 166 56 1 -0.381078571 1.42857119 -1.046203407
#> 167 56 2 0.116047733 -0.48214099 0.172260011
#> 168 56 3 0.892492885 0.99238818 -0.307020751
#> 171 57 3 1.452055280 -0.10744815 1.643828484
#> 172 58 1 2.556923589 -0.77320677 0.814559724
#> 173 58 2 1.072728070 -0.73627880 0.825113161
#> 174 58 3 -1.178914989 0.81570668 -0.345773922
#> 176 59 2 0.053855088 -0.67104663 -0.643214383
#> 177 59 3 -0.234343833 -0.42158960 0.942059477
#> 181 61 1 -0.816198742 -0.69541367 0.794574264
#> 182 61 2 0.295544263 -0.38354996 -0.914850956
#> 184 62 1 -0.280015436 -1.10798826 0.819669363
#> 185 62 2 -0.063043628 -0.95593877 1.521035738
#> 186 62 3 -0.132833831 -0.63576842 0.265354790
#> 187 63 1 0.629361770 0.76675745 0.619066940
#> 188 63 2 -0.641231532 0.68695810 0.471080837
#> 189 63 3 -0.104018599 1.72142669 0.463144213
#> 190 64 1 -1.388668827 0.85130925 -0.160161363
#> 191 64 2 0.437214206 0.42990828 -0.035685472
#> 192 64 3 0.315862087 -1.05527774 -0.574684816
#> 195 65 3 0.812534989 -0.31946356 -0.502357106
#> 196 66 1 0.275042593 0.47360616 1.088076265
#> 197 66 2 0.006009411 0.81251610 -0.392953019
#> 198 66 3 2.010186412 0.25661233 -0.660461119
#> 199 67 1 0.313808823 -2.14876584 -0.149025127
#> 200 67 2 -0.846162712 0.69010855 -0.875485298
#> 201 67 3 -0.134641045 -1.77244383 1.699001571
#> 204 68 3 0.204499683 -0.74870221 -0.080948993
#> 205 69 1 -0.341768421 -0.79432104 2.446781428
#> 206 69 2 1.842157648 0.30078439 0.383899034
#> 207 69 3 -0.205909535 0.05466585 -1.052171578
#> 209 70 2 0.242188060 -1.16518670 -0.630819250
#> 210 70 3 0.053455720 0.26055583 -0.953595979
#> 211 71 1 -0.125146310 -2.41711628 -0.079982465
#> 212 71 2 0.247787238 1.14908502 1.062695902
#> 216 72 3 -0.814967320 0.48619572 -0.764770258
#> 220 74 1 -0.042837457 -0.20777098 -0.542495361
#> 221 74 2 -1.281559297 0.90728141 -2.094578220
#> 222 74 3 0.967582242 0.81142513 0.378050059
#> 224 75 2 -2.166425254 -0.45430696 -0.587104530
#> 225 75 3 -0.303348223 -0.31572854 0.100086359
#> 227 76 2 1.427395820 -1.01659466 0.659843996
#> 228 76 3 -0.619946595 2.02996478 -0.626745356
#> 230 77 2 0.267551749 -1.58790685 0.876503187
#> 232 78 1 0.234340520 -0.72310219 2.280390353
#> 234 78 3 1.898439401 -2.14081548 -0.573636034
#> 237 79 3 1.764724810 0.49461317 0.900082480
#> 238 80 1 0.506063430 -1.52664365 1.989430257
#> 241 81 1 1.372876146 -0.56354343 0.204160839
#> 242 81 2 0.594581979 -1.44585342 0.044228525
#> 243 81 3 0.809307437 -0.47655578 0.627097488
#> 244 82 1 -0.929351716 1.01460047 -0.947249554
#> 245 82 2 -0.968882573 -0.11802003 -1.122826944
#> 246 82 3 -0.563483049 -0.35432184 -0.020323649
#> 250 84 1 0.412530895 1.44473649 1.056927128
#> 253 85 1 -0.279921977 -0.73561961 -0.066451341
#> 254 85 2 -0.184466622 -0.01523526 -0.608107881
#> 256 86 1 0.599068143 -0.77089599 0.393169958
#> 257 86 2 -0.345024460 -1.91152294 -0.385205931
#> 258 86 3 0.328683628 0.17789966 -0.609263122
#> 259 87 1 -0.002001793 0.19632069 -0.384385146
#> 260 87 2 -1.643640470 0.05004416 -0.901423669
#> 262 88 1 1.311300782 -0.13668239 0.561821259
#> 263 88 2 -0.725708977 1.22750061 -1.757278522
#> 266 89 2 0.739965537 -0.42990567 2.506001719
#> 267 89 3 -0.379227989 -0.65191632 -0.980587165
#> 268 90 1 0.855040406 -1.32275532 1.566125055
#> 269 90 2 0.929726811 -0.61100236 -0.758867435
#> 271 91 1 0.575606727 0.22113162 -0.327150452
#> 273 91 3 0.873922726 1.00351963 1.519723106
#> 275 92 2 0.631952946 -0.87353493 -0.402339950
#> 276 92 3 0.489051671 -0.77371083 -1.495466433
#> 279 93 3 -0.115346633 -0.48962671 -1.813867623
#> 280 94 1 0.402961199 -0.66608550 -0.951775432
#> 281 94 2 -1.329553215 -1.08965423 1.126852099
#> 282 94 3 0.850032275 -1.04090695 0.139889065
#> 283 95 1 1.105681923 0.50160668 0.100339977
#> 284 95 2 0.404141906 0.04135376 -1.204528629
#> 285 95 3 -0.123141511 -0.05308168 -0.083458296
#> 289 97 1 -0.219531175 -0.13683359 -1.190506799
#> 291 97 3 -1.582876585 0.33701264 0.777407773
#> 292 98 1 0.084967784 0.76451066 -0.221089724
#> 294 98 3 -0.023462572 -0.16096887 0.115230043
#> 295 99 1 0.084693918 1.50726103 1.533269573
#> 296 99 2 -0.325065508 -0.12169384 -0.655774460
#> 297 99 3 0.505923564 -0.24341478 0.858378701
#> 298 100 1 0.415272046 0.70815719 -1.187670552
#> 300 100 3 0.033445330 -0.31655127 -0.266362163