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:
data < – read.table(text=”
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
,
https://blog.csdn.net/SThranduil/article/details/71710283 copyright statement: this article original articles for bloggers, reproduced please attach link to blog!
Read More:
- Error in lm.fit (x, y, offset = offset, singular.ok = singular.ok ,…): no (non Na) cases available
- R language error messages and related solutions
- R language notes – sample() function
- Usage and examples of three important functions of tidyr package in R language: gather, spread and separate
- Installation and use of R language ggmap package
- Renaming the column name of data frame in R language
- Error analysis of multiple linear regression in R language model.frame.default
- R language – path setting and working directory modification
- R language error in hist.default ():’x’must be a value
- Solutions to the failure of R language loading rjava
- The sparse matrix of R language is too large to be used as.matrix
- Analysis of R language error replacement has length zero problem
- Solving the problem of saving object set by save() function in R language
- R language error in match.names (clabs, names(xi)) :
- R language error:‘ namespace:lazyeval There is no exit_ The object is eval
- Trivia: How does R language solve Error in ts(x):’ts’ object must have one or more observations
- R language-Error in file(out, “wt”): Unable to open the link problem solved
- 13. R language: Error in match.names(clabs, names(xi)): The name is not relative to the original name
- In R language, for loop or array truncation, the following error occurs only 0’s may be mixed with negative subscripts
- R language loading xlsx error error: JAVA_HOME cannot be determined from the Registry