What is the is.character() function in R?
In R, the character objects represent string values. The as.character() function transforms the values into character objects. We can use the is.character() function to determine whether the provided object is a character as follows:
Syntax
is.character(object)
The syntax for the is.character() function in R
Parameters
The is.character() function takes a single parameter value, representing the object whose type we want to determine.
Return value
The is.character() function returns TRUE if the provided object is a character. Otherwise, it returns FALSE.
Example
# Vector of character datatypevec1 <- c("Welcome", "to", "Educative!")# Vector of numeric datatypevec2 <- c(1, 0, 1)# Using the is.character() functionis.character(vec1)is.character(vec2)
Explanation
Line 2: We create a vector
vec1of character datatypes.Line 4: We create a vector
vec2of numeric datatypes.Lines 6–7: We use
is.character()to determine the type of created objects.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved