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