0

Kindly suggest a code for the below method.

If Hba column has NA then delete the entire row of that ID's. That deletion should be done within the same dataset, not by creating the new dataset.

for Eg; here the data with table name (Hba1c_data)

ID  G Hba var1 var2
123 M 7.1 45   78
654 F 8.1 78   32
159 F NA  57   52
147 M NA  NA   NA

Expected Output (should be in the same table(Hba1c_data))

ID  G Hba var1 var2
123 M 7.1 45   78
654 F 8.1 78   32

Thanks in advance!

NelsonGon
  • 13,015
  • 7
  • 27
  • 57

2 Answers2

2

I think, this should do the trick:

Hba1c_data <- Hba1c_data[!is.na(Hba1c_data$Hba),]
Steffen
  • 206
  • 1
  • 7
0

Does this work:

library(dplyr)
df %>% filter(!is.na(Hba))
# A tibble: 2 x 5
     ID G       Hba  var1  var2
  <dbl> <chr> <dbl> <dbl> <dbl>
1   123 M       7.1    45    78
2   654 F       8.1    78    32
Karthik S
  • 11,348
  • 2
  • 11
  • 25