1.5 NA

NA é uma constante lógica de tamanho 1 que contém um indicador de valor faltante. A codificação NA pode identificar três situações.

  • ‘Not Available’: não disponível, e.g. perguntar ‘que horas são?’ e não haver relógio disponível.
  • ‘Not Applicable’: não aplicável, e.g. perguntar ‘o senhor está grávido?’
  • ‘Not Announced/Answered’: não anunciado/não respondido, e.g. ficar em silêncio em um interrogatório.
  • ‘Not Accessed’, e.g. a página Moodle do aluno não foi acessada durante todo o semestre.
?NA
(x <- c(NA, 1:3, NA, 1000))
## [1]   NA    1    2    3   NA 1000
is.na(x)
## [1]  TRUE FALSE FALSE FALSE  TRUE FALSE
sum(is.na(x))
## [1] 2
anyNA(x)
## [1] TRUE

A biblioteca VIM de (Kowarik and Templ 2016) fornece ferramentas para visualização de valores faltantes e imputados.

library(VIM)
(a <- aggr(sleep, sortVars = TRUE))

## 
##  Variables sorted by number of missings: 
##  Variable      Count
##      NonD 0.22580645
##     Dream 0.19354839
##     Sleep 0.06451613
##      Span 0.06451613
##      Gest 0.06451613
##   BodyWgt 0.00000000
##  BrainWgt 0.00000000
##      Pred 0.00000000
##       Exp 0.00000000
##    Danger 0.00000000
## 
##  Missings in variables:
##  Variable Count
##      NonD    14
##     Dream    12
##     Sleep     4
##      Span     4
##      Gest     4
summary(a)
## 
##  Missings per variable: 
##  Variable Count
##   BodyWgt     0
##  BrainWgt     0
##      NonD    14
##     Dream    12
##     Sleep     4
##      Span     4
##      Gest     4
##      Pred     0
##       Exp     0
##    Danger     0
## 
##  Missings in combinations of variables: 
##         Combinations Count   Percent
##  0:0:0:0:0:0:0:0:0:0    42 67.741935
##  0:0:0:0:0:0:1:0:0:0     3  4.838710
##  0:0:0:0:0:1:0:0:0:0     2  3.225806
##  0:0:0:0:0:1:1:0:0:0     1  1.612903
##  0:0:1:0:1:0:0:0:0:0     2  3.225806
##  0:0:1:1:0:0:0:0:0:0     9 14.516129
##  0:0:1:1:0:1:0:0:0:0     1  1.612903
##  0:0:1:1:1:0:0:0:0:0     2  3.225806

Referências

Kowarik, Alexander, and Matthias Templ. 2016. “Imputation with the R Package VIM.” Journal of Statistical Software 74 (7): 1–16. https://doi.org/10.18637/jss.v074.i07.