filter
in dplyr
will drop NA
s when we filter a variable bigger or less than certain value.
require(dplyr)
## Loading required package: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
test <- data.frame(value = c(rep(NA,3), -3:3))
The result of filter
function
dplyr::filter(test, value > 0)
## value
## 1 1
## 2 2
## 3 3
The result of base functions
test$value[test$value > 0]
## [1] NA NA NA 1 2 3
Conclusion
If we use filter, the result would drop NA
observations.
if we use base functions, the NA
s are remained.