- any() function in R checks whether at least one value remains true of the logical vector
- all() function in R checks whether all values remains true of the logical vector
Example of any function in R:
# any function in R v1 <- c(3,4) v2 <- c(101,4) t <- c(1,2,3,4,5,6,7,8) any(v1 %in% t)
the above example checks whether any value of v1 present in t so the output will be
# any function in R any(v2 %in% t)
the above example checks whether any value of v2 present in t so the output will be
Example of all function in R:
# all function in R all(v2 %in% t)
the above example checks whether all value of v2 present in t so the output will be
Example of any function in R for data frame:
Lets use same mtcars data frame to depict example of any function in R
# any function in R for mtcars data frame any(mtcars$cyl %in% 4)
When we execute above code it checks whether atleast one value of cyl column of mtcars data frame have value 4 in it
So the output will be
Example of all function in R for data frame:
Lets use same mtcars data frame to depict example of all function in R
# all function in R for mtcars data frame all(mtcars$cyl %in% 4)
When we execute above code it checks whether all the values of cyl column of mtcars data frame have value 4 in it
So the output will be
# all function in R for mtcars data frame all(mtcars$am %in% c(1,0))
When we execute above code it checks whether all the values of am column of mtcars data frame have value 0 or 1 in it, which is TRUE
So the output will be