convert variable from int to string in R
Code snippet on how to convert variable from int to string in R
x <- 5
str_x <- as.character(x)
The code above is used to convert a variable stored as an integer into a character string. It first creates an integer variable, x, equal to 5. The second line is where the conversion of the integer x into a character string occurs. It does this by using the ‘as.character’ command and assigning whatever is input into the command (in this case x) to a new variable, here named str_x. This new variable, str_x, is now a character string with the same value as x.