Home > OS >  How to get rid of a group of values if one of the rows shows an NA value?
How to get rid of a group of values if one of the rows shows an NA value?

Time:07-21

My data is organized by PVC value. Most of them have 1, 2, or 3 rows assigned per PVC value. But, sometimes the volume values aren't all included. For instance, a PVC value might have 3 rows, but only 1 of them actually has a volume whereas the other two are NA.

If a certain PVC value has an NA at all (doesn't matter the amount), I want to get rid of ALL the PVC rows. Basically, I don't just want to get rid of the NA volume values but also the corresponding PVC rows.

Here is my data:


> dput(nests2020)
structure(list(PVC = c("BX6V", "BX6V", "BT0Y", "AS2R", "AS2R", 
"AS2R", "AR17", "AR17", "AR17", "BX9Z", "BWY5", "BWY5", "BWY5", 
"AZ2B", "AZ2B", "BW4L", "BW4L", "BMP4", "BMP4", "BMP4", "BBHP", 
"BBHP", "BXC1", "BXC1", "BXC1", "BUJJ", "BUJJ", "AR2X", "24N", 
"24N", "BNSR", "BNSR", "BNSR", "BS2W", "BS2W", "BS2W", "ALB4", 
"ALB4", "ALB4", "BA90", "BA90", "BA90", "BXHF", "BXHF", "BXHF", 
"BV0Z", "BV0Z", "BV0Z", "BN22", "BN22", "ANUA", "ANUA", "ANUA", 
"AA2X", "AA2X", "AA2X", "BW0C", "BW0C", "BW0C", "BPYY", "BPYY", 
"BPYY", "AB96", "AB96", "AB96", "BXMU", "BYBC", "AWJR", "AWJR", 
"AWJR", "AYLM", "BSAT", "BSAT", "BN1X", "BN1X", "BN1X", "AD1J", 
"AD1J", "AD1J", "694", "694", "694", "BYW8", "BYW8", "532", "532", 
"532", "BVW0", "BVW0", "BVW0", "BTPJ", "BTPJ", "BV7W", "BV7W", 
"BXFD", "BXFD", "BXFD", "BT5R", "BT5R", "BT5R", "UZJ", "UZJ", 
"UZJ", "AYN5", "AYN5", "AYN5", "BVUA", "BVUA", "BVUA", "AR76", 
"AR76", "AR76", "BUDD", "BUDD", "BUDD", "BUTT", "BUTT", "BUTT", 
"CLF1", "CLF1", "CLF1", "CLF2", "CLF2", "CLF2", "CLF3", "CLF3", 
"CLF3", "CLF4", "CLF4", "CLF5", "CLF5", "CLF5", "CLF6", "CLF6", 
"CLF6", "ATZ5", "ATZ5", "ATZ5", "AZT9", "AZT9", "AZT9", "BX93", 
"BX93", "BL0F", "BL0F", "BZ39", "BHDY", "BHDY", "AS1J", "AS1J", 
"AS1J", "AW0F", "AW0F", "AW0F", "BUDC", "BUDC", "BUDC", "BZ0X", 
"BZ0X", "BZ0X", "BHDT", "BHDT", "BHDT", "BTYY", "BTYY", "BTYY", 
"BHDP", "BHDP", "BHDP", "BZ7B", "BZTB", "BZTB", "AMU4", "AMU4", 
"BZ9D", "BZ9D", "AUMD", "BZ73", "BZ73", "BC78", "BC78", "BC78", 
"BX1F", "BX1F", "CDD8", "CDD8", "BZ8R", "BZ8R", "AR7H", "AR7H", 
"AR7H", "BZ9U", "BZ9U", "BPS4", "BPS4", "BPS4", "619763-", "619763-", 
"619763-"), Egg_order = c(9L, 9L, 1L, 3L, 9L, 9L, 9L, 9L, 9L, 
1L, 9L, 9L, 9L, 9L, 9L, 2L, 1L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 1L, 2L, 3L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 1L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 2L, 1L, 3L, 9L, 9L, 
9L, 2L, 1L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 3L, 9L, 9L, 
9L, 2L, 3L, 1L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 1L, 2L, 
3L, 2L, 1L, 3L, 9L, 9L, 9L, 9L, 1L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 1L, 2L, 9L, 9L, 9L, 1L, 2L, 9L, 9L, 9L, 9L, 9L, 9L), Edat = c(NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA), Year = c("2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020"), Volume = c(54.90113795712, 59.62178709136, 
45.80383827316, 59.81006985316, 62.70707802527, 56.1273221875, 
63.21010595736, 66.5262124352, 61.594321194, 50.48956845791, 
56.75091552075, 56.26261601046, 53.62081629723, 62.42521148416, 
61.177367467575, 59.9552569525, 63.43399584, 56.47841663436, 
57.222675918, 52.304776127035, 58.83469694168, 50.98230704128, 
63.624675192925, 63.31446914976, 63.9174637444, 55.02375677844, 
63.224630766945, 52.300100652345, 56.92824970146, 62.42583127536, 
66.45215196714, 63.1189393065, 62.392345714755, 66.89281190138, 
59.19164251875, 59.31163591964, 59.955422968, 56.60001529504, 
54.067787456445, 59.8163449306, 58.56891343416, 54.77753171072, 
57.5239411273, 50.311441571375, 65.53436494478, 63.25923172085, 
60.29423741856, 51.78630063212, 61.172330502015, 63.24037180812, 
68.749480895, 62.710430438875, 55.23772542639, 69.87011478975, 
56.949726247875, 61.31504604378, 57.19289071776, 61.53957511956, 
49.7580224492, 63.41422664248, 65.30228568, 60.63207693376, 65.08487697264, 
62.22773398275, 53.21366834688, 57.269236933105, 56.06292544047, 
60.6414141945, 55.9768363002, 57.26929882347, 61.140912583225, 
64.37522085984, 52.25351891028, 61.98246361134, 57.77898287616, 
57.1002084225, 57.360009682, 54.94928621184, 58.75063258232, 
69.76345436866, 67.593261519625, 69.11846352896, 55.71023686263, 
58.2163582158, 59.211320484375, 63.72789773274, 55.7362695296, 
64.47170546586, 64.73422846, 61.36318173312, 58.378566558435, 
61.71008575476, 59.941176349565, 63.26646553174, 50.992284826, 
57.3318917876, 62.70075001008, NA, NA, 59.89783472566, 63.86995611648, 
60.4029063168, 55.07649453384, 52.31282036953, 58.99895374632, 
48.719745909265, 54.64171455918, 53.94298166488, 55.901870771215, 
65.56774498248, 62.90534168064, 61.41945817656, 66.919009044945, 
61.96489394508, 65.034574992, 64.729103016375, 64.17060330774, 
65.389800483105, NA, NA, NA, 59.63599996495, 64.931122722235, 
56.65922655302, 61.46651134202, 57.8852783784, 62.39388067622, 
60.57483493292, 68.560542815265, 50.53489856096, 55.1894951475, 
59.70034212426, 65.759746701, 68.88087058048, 63.50592726864, 
66.33374108827, 62.6025867725, 55.759603578, 65.46998937188, 
58.291694391, 61.929869128335, 58.25452151168, 57.668796184, 
61.51978314644, 59.077765222, 51.97989700736, 67.74748109649, 
61.385301165465, 62.73494474108, 59.348627260065, 62.3845024, 
61.36470920764, 62.3774705984, 55.427547552, 61.75144610856, 
53.577579666125, 59.71898703552, 65.023882682, 57.25868605056, 
52.59843947592, 70.35706978304, 72.86003463108, 60.97881564024, 
63.97224438285, 66.69567794778, 52.552747603125, 67.54180590974, 
65.48167452344, 58.019245754975, 66.86380993734, 55.0060021875, 
65.354910896, 58.56705458242, 60.14823217854, NA, 65.32265549376, 
56.62567208992, 60.755647584555, 47.930963051385, 70.85907421769, 
58.9073356885, 66.669284526655, 61.90533395658, 55.427671193535, 
51.11915501764, 57.75161328729, 60.414661135215, 55.0827760385, 
58.568968454985, 52.450078377015, 44.38977949966, 60.447308392235, 
57.68219240392, 64.576311296, 58.1207602635, 52.32109377404, 
59.817989378875, 59.4732663096, 53.018981153775), count = c(2L, 
2L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L, 2L, 2L, 1L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
1L, 1L, 3L, 3L, 3L, 1L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 
1L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
2L, 2L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L), egg_status = c("none", "none", "complete", 
"estimated", "estimated", "estimated", "none", "none", "none", 
"complete", "none", "none", "none", "none", "none", "complete", 
"complete", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "complete", "complete", 
"complete", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", NA, NA, 
NA, "none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "complete", "complete", "complete", "none", 
"none", "none", "complete", "complete", "none", "none", "none", 
"none", "none", "none", "none", "none", "estimated", "estimated", 
"estimated", "none", "none", "none", "complete", "complete", 
"complete", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "complete", "complete", "complete", "complete", 
"complete", "complete", "none", "none", "none", "none", "complete", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"none", "none", "none", "none", "none", "none", "none", "none", 
"complete", "complete", "none", "none", "none", "complete", "complete", 
"none", "none", "none", "none", "none", "none"), estimated_Egg_order = c(9L, 
9L, 1L, 3L, 1L, 2L, 9L, 9L, 9L, 1L, 9L, 9L, 9L, 9L, 9L, 2L, 1L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 1L, 2L, 3L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 1L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 2L, 1L, 3L, 9L, 9L, 9L, 2L, 1L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 1L, 2L, 3L, 9L, 9L, 9L, 2L, 3L, 1L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 1L, 2L, 3L, 2L, 1L, 3L, 9L, 9L, 9L, 9L, 
1L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 1L, 2L, 9L, 9L, 9L, 1L, 2L, 
9L, 9L, 9L, 9L, 9L, 9L), ID_NIU = c(56L, 56L, 40L, 16L, 16L, 
16L, 11L, 11L, 11L, 58L, 54L, 54L, 54L, 23L, 23L, 53L, 53L, 32L, 
32L, 32L, 26L, 26L, 59L, 59L, 59L, 46L, 46L, 12L, 1L, 1L, 35L, 
35L, 35L, 38L, 38L, 38L, 8L, 8L, 8L, 25L, 25L, 25L, 61L, 61L, 
61L, 48L, 48L, 48L, 34L, 34L, 10L, 10L, 10L, 5L, 5L, 5L, 52L, 
52L, 52L, 37L, 37L, 37L, 6L, 6L, 6L, 62L, 63L, 20L, 20L, 20L, 
21L, 39L, 39L, 33L, 33L, 33L, 7L, 7L, 7L, 4L, 4L, 4L, 64L, 64L, 
2L, 2L, 2L, 51L, 51L, 51L, 42L, 42L, 49L, 49L, 60L, 60L, 60L, 
41L, 41L, 41L, 80L, 80L, 80L, 22L, 22L, 22L, 50L, 50L, 50L, 13L, 
13L, 13L, 45L, 45L, 45L, 47L, 47L, 47L, 74L, 74L, 74L, 75L, 75L, 
75L, 76L, 76L, 76L, 77L, 77L, 78L, 78L, 78L, 79L, 79L, 79L, 17L, 
17L, 17L, 24L, 24L, 24L, 57L, 57L, 31L, 31L, 66L, 30L, 30L, 15L, 
15L, 15L, 19L, 19L, 19L, 44L, 44L, 44L, 65L, 65L, 65L, 29L, 29L, 
29L, 43L, 43L, 43L, 28L, 28L, 28L, 68L, 72L, 72L, 9L, 9L, 70L, 
70L, 18L, 67L, 67L, 27L, 27L, 27L, 55L, 55L, 73L, 73L, 69L, 69L, 
14L, 14L, 14L, 71L, 71L, 36L, 36L, 36L, 3L, 3L, 3L)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -199L))

Let me know if any clarification is needed.

CodePudding user response:

You may try

library(dplyr)

nests2020  %>%
  group_by(PVC) %>%
  filter(sum(is.na(Volume)) == 0) 
  •  Tags:  
  • r
  • Related