Make subset and keep values NA

3

I'm sure there's a way to make subset and keep the NA values in R. However, when I apply this function, the NA values are also disappearing from my base. I'm just using the formula below:

dados1<-data.frame(subset(dados,V2!="CNPJ"))

So you're missing the values of V2 that are in NA. What is the best way to do this subset?

    
asked by anonymous 13.12.2016 / 19:22

2 answers

3

The way I discovered was to put the is.na in the programming, ie:

dados1<-data.frame(subset(dados,V2!="CNPJ"|is.na(V2)))
    
13.12.2016 / 19:34
1

One option (perhaps uglier) is to use the subsetting that the [ operator provides:

dados[dados$V2 != "CNPJ",]

This operation holds the lines containing NA .

    
17.12.2016 / 01:53