# R language: na.fail and na.omit

In practice, the data set is rarely complete, and in many cases, the sample will contain several missing values NA, which is troublesome in data analysis and mining.
R language can improve the omit value of samples by na.fail and na.omit.
The

na. Fail (& lt; Vector a>) : If vector A contains at least 1 NA, error is returned; If NA is excluded, return the original vector ana. Omit (& LT; Vector a>) : Return the vector aattr (na.omit (& LT); Vector a>) , “na.action”) : returns the subscript of na in vector a. Na: determines whether the element in the vector is na

Example:

data< – c (1, 2, NA, 2,4,2,10, NA, 9)
data. NA. Omit< – na. Omit (data)
data. Na. Omit the
[1] 1 2 2 and 4 2 10 9
attr (, “na. The action”)
3 8 [1]
attr (” class “)
[1] “omit”

attr (data. Na. Omit, “na. The action”)
3 8 [1]
attr (” class “)
[1] “omit”

can also be used! X mode conveniently deletes NA. Such as:

a< – c (1, 2, 3, NA, NA, 2, NA, 5)
a[!is.na(a)]
[1] 1 2 3 2 5

.
which is for na na is used to determine whether the element in the vector, returns the result: c (FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE), namely the elements within a as na, its corresponding subscript elements is TRUE, otherwise is FALSE. ! X is the non-logical operator,! Is. Na (a) means that the element inside a is not Na, and its subscript element is TRUE and FALSE conversely. After indexing through A [! Is.na (a)], the element that is not Na in A can be taken out and filtered.
The functions Na. fail and Na. omit can be applied not only to vectors but also to matrices and data boxes.
Example:

a b c d e f
NA 1 1 1 1 1
1 NA 1 1 1 1
1 1 NA 1 1 1
1 1 1 NA 1 1
1 1 1 1 NA 1
1 1 1 1 1 NA”,header=T)
na.omit(data)
data
> [1] a b c d e f
< 0 line & gt; (or 0-length row.names)

— — — — — — — — — — — — — — — — — — — — —
the author: SThranduil
source: CSDN
,