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:
is.character(object)
The is.character()
function takes a single parameter value, representing the object whose type we want to determine.
The is.character()
function returns TRUE
if the provided object is a character. Otherwise, it returns FALSE
.
# 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)
Line 2: We create a vector vec1
of character datatypes.
Line 4: We create a vector vec2
of numeric datatypes.
Lines 6–7: We use is.character()
to determine the type of created objects.
Free Resources