Skip to content
Related Articles

Related Articles

Convert a Numeric Object to Character in R Programming – as.character() Function
  • Last Updated : 16 Jun, 2020

as.character() function in R Language is used to convert a numeric object to character object.

Syntax: as.character(x)

Parameters:
x: Numeric Object

Example 1:




# R program to convert a numeric object
# to character object
  
# Calling as.character() function
as.character(1)
as.character(2 + 3)
as.character(1.5)

Output:

[1] "1"
[1] "5"
[1] "1.5"

Example 2:




# R program to convert a numeric object
# to character object
  
# Creating a vector
x1 <- c(1, 2, 3, 4)
x2 <- c(-1, 2, 1.5, -3)
  
# Calling as.character() function
as.character(x1)
as.character(x2)

Output:

[1] "1" "2" "3" "4"
[1] "-1"  "2"   "1.5" "-3" 
My Personal Notes arrow_drop_up
Recommended Articles
Page :