To convert a float to a string in R, you can use the as.character()
function.
In this example,
3.14
to a variable float1
.as.character()
function to convert the float to a string and store the result in a variable str1
.str1
.float1 <- 3.14
str1 <- as.character(float1)
print(paste('String value is:', str1))
String value is: 3.14
In this example,
10.5
to a variable float2
.as.character()
function to convert the float to a string and store the result in a variable str2
.str2
.float2 <- 10.5
str2 <- as.character(float2)
print(paste('String value is:', str2))
String value is: 10.5
In this tutorial, we learned How to convert Float to String in R language with well detailed examples.