Convert a Numeric Object to Character in R Programming – as.character() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

[1] "1" "2" "3" "4"
[1] "-1"  "2"   "1.5" "-3" 
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.