Tutorial by Examples

anyNA reports whether any missing values are present; while is.na reports missing values elementwise: vec <- c(1, 2, 3, NA, 5) anyNA(vec) # [1] TRUE is.na(vec) # [1] FALSE FALSE FALSE TRUE FALSE ìs.na returns a logical vector that is coerced to integer values under arithmetic operation...
When reading tabular datasets with the read.* functions, R automatically looks for missing values that look like "NA". However, missing values are not always represented by NA. Sometimes a dot (.), a hyphen(-) or a character-value (e.g.: empty) indicates that a value is NA. The na.strings ...
The symbol NA is for a logical missing value: class(NA) #[1] "logical" This is convenient, since it can easily be coerced to other atomic vector types, and is therefore usually the only NA you will need: x <- c(1, NA, 1) class(x[2]) #[1] "numeric" If you do need a s...
NA is a logical type and a logical operator with an NA will return NA if the outcome is ambiguous. Below, NA OR TRUE evaluates to TRUE because at least one side evaluates to TRUE, however NA OR FALSE returns NA because we do not know whether NA would have been TRUE or FALSE NA | TRUE # [1] TRUE ...
Recoding missing values Regularly, missing data isn't coded as NA in datasets. In SPSS for example, missing values are often represented by the value 99. num.vec <- c(1, 2, 3, 99, 5) num.vec ## [1] 1 2 3 99 5 It is possible to directly assign NA using subsetting num.vec[num.vec == 99]...

Page 1 of 1