-1

How can I remove NAs in my dataset after ungrouping them in a character vector?

this is the data set :

Mno     drugs

100173  9
100173  3
100173   NA
100173   NA
100463  18
100463  18
100463  1
100463   NA
100463   NA
100463   NA
10061   18
10061   9
10061   2


a <- is.na(progression_diab)

I need the output like this:

s.no     Mno     drug3

1       100173      9
2       100173      3
5       100463      18
6       100463      18
7       100463      1
11      10061      18
12      10061      9
13      10061      2
14      10061      3
16      101793     0
NelsonGon
  • 12,469
  • 5
  • 25
  • 52

1 Answers1

2

Assuming progression_dab is a character vector, like x below, you can do:

x <- c("a", NA, "b")

na.omit(x)
## "a" "b"

or:

theNAs <- is.na(x) # the indices of the NAs
x[!theNAs] # remove theses indices to x
## "a" "b"
Stéphane Laurent
  • 59,551
  • 14
  • 99
  • 196