R – Check if Type of Vector is Logical
To check if type of given vector is logical in R, call is.logical() function and pass the vector as argument to this function. If the given vector is logical, then is.logical() returns TRUE, or else, it returns FALSE.
The syntax to call is.logical() to check if type of vector
x is logical is
The function returns a logical value.
In the following program, we take a vector in
x, and check if this vector is a logical vector using
is.logical() function. We print the value returned by
x <- c(TRUE, FALSE, NA, FALSE) result <- is.logical(x) print(result)
Now, let us take a vector
x of some type other than logical, and check the value returned by
x is not logical,
is.logical() must return
x <- c(25, 84, 10) result <- is.logical(x) print(result)
In this R Tutorial, we learned how to check if given vector is of type logical, using is.logical() function, with the help of examples.