Open In App

Check if an Object is of Type Character in R Programming – is.character() Function

Improve
Improve
Like Article
Like
Save
Share
Report

is.character() function in R Language is used to check if the object passed to it as argument is of character type.

Syntax: is.character(x)

Parameters:
x: Object to be checked

Example 1:




# R program to check if 
# object is a character
  
# Creating a vector
x1 <- 4
x2 <- c("a", "b", "c", "d")
x3 <- c(1, 2, "a", 3, "b")
  
# Calling is.character() function
is.character(x1)
is.character(x2)
is.character(x3)


Output:

[1] FALSE
[1] TRUE
[1] TRUE

Example 2:




# R program to check if 
# object is a character
  
# Creating a matrix
x1 <- matrix(letters[1:9], 3, 3)
  
# Calling is.character() function
is.character(x1)


Output:

[1] TRUE

Last Updated : 16 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads