Create a function that accepts two arguments, an integer and a vector of integers. It returns TRUE if the integer is present in the vector, otherwise it returns FALSE.
Let us create a function which returns TRUE and FALSE based on the condition
num_check <- function(num,v){
for (item in v){
if (item == num){
return(TRUE)
}
}
return(FALSE)
}
Now let us check whether it is working or not.
num_check(2,c(1,2,3))
Output
TRUE
num_check(2,c(1,4,5))
Output
FALSE