In R, you can convert an integer to a string using the toString()
function or by concatenating the integer with an empty string.
In this example,
42
to a variable named num
.toString()
function to convert the integer num
to a string and store the result in the variable strNum
.toString()
function converts the integer to its string representation.# Convert Integer to String using toString()
num <- 42
strNum <- toString(num)
cat('String representation of integer:', strNum, '\n')
String representation of integer: 42
In this example,
-10
to a variable named negativeNum
.negativeNum
with an empty string and store the result in the variable strNegativeNum
.# Convert Negative Integer to String using Concatenation
negativeNum <- -10
strNegativeNum <- paste(negativeNum, '')
cat('String representation of negative integer:', strNegativeNum, '\n')
String representation of negative integer: -10
In this tutorial, we learned How to Convert Integer to String in R language with well detailed examples.