A character object in R is used to interpret string values. We convert R objects into character values with the as.character() function. The as.character() function is used to convert a numeric object to a character object.
as.character() in R
The as.character() is a built-in R function that generates a string representation of a provided argument. The as.character() function returns the string of 1’s and 0’s or a character vector of traits depending on the nature of the argument supplied.
The as.character() function takes one argument x that is an object of class fingerprint, featvec, or feature.
The as.character() function returns the string of 1’s and 0’s or a character vector of features.
data <- as.character(3.14) data
In this example, we passed the floating value as an argument, and as.character() function converts into a character vector.
Convert a numeric object to a character
To convert a numeric object to a character in R, use the as.character() function. To create a vector in R, use the c() function. We will create two numeric vectors and convert those vectors into characters.
data1 <- c(11, 21, 31, 41) data2 <- c(-11, 21, 1.5, -31) as.character(data1) as.character(data2)
 "11" "21" "31" "41"  "-11" "21" "1.5" "-31"
How to check character type in R
To check the character type in R, use the is.character() function. The is.character() function returns TRUE if the argument is of character type; otherwise returns FALSE.
data1 <- 3.14 data2 <- c(-11, 21, 1.5, -31) co1 <- as.character(data1) co2 <- as.character(data2) co1 co2 is.character(co1) is.character(co2)
 "3.14"  "-11" "21" "1.5" "-31"  TRUE  TRUE
And we get the TRUE for both the output. So that means we successfully converted a numeric object to a character vector.
R as.character() function converts the provided argument to character type. The as.character() and is.character() methods are generic functions. That is it for this tutorial.
Krunal Lathiya is an Information Technology Engineer by education and web developer by profession. He has worked with many back-end platforms, including Node.js, PHP, and Python. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language. Krunal has written many programming blogs, which showcases his vast expertise in this field.