all()
and any()
are functions which given a set of logical vectors returns TRUE or FALSE:all()
are all the values true?any()
is at least one value true?
all(..., na.rm = FALSE)
any(..., na.rm = FALSE)
Parameters:
- x: logical vector
- na.rm: If TRUE NA values are removed before the result is computed
x <- sort(round(rnorm(12), 1))
x
## [1] -1.0 -0.9 -0.9 -0.5 -0.4 -0.3 0.1 0.4 0.7 1.1 1.1 1.6
all(x < 0)
## [1] FALSE
any(x < 0)
## [1] TRUE
range(iris$Sepal.Length)
## [1] 4.3 7.9
boxplot(iris$Sepal.Length, col = 'gold')
all(iris$Sepal.Length > 5)
## [1] FALSE
any(iris$Sepal.Length > 5)
## [1] TRUE
all(iris$Sepal.Length > 4)
## [1] TRUE
any(iris$Sepal.Length > 8)
## [1] FALSE
na.rm
parameter:
The airquality dataset contains
NA
values:summary(airquality$Ozone)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 1.00 18.00 31.50 42.13 63.25 168.00 37
range(airquality$Ozone, na.rm = TRUE)
## [1] 1 168
boxplot(airquality$Ozone, col ='pink')
all(airquality$Ozone > 0)
## [1] NA
any(airquality$Ozone > 0)
## [1] TRUE
all(airquality$Ozone > 0 , na.rm = TRUE)
## [1] TRUE
any(airquality$Ozone > 0)
## [1] TRUE
any(airquality$Ozone < 0, na.rm = TRUE)
## [1] FALSE
No comments:
Post a Comment