-4

Does anyone know how to do the convert numeric value into string value in R?

For example:

c(1,2,3,4)

into

c("Region 1", "Region 2", "Region 3", "Region 4")
David Arenburg
  • 91,361
  • 17
  • 137
  • 196

1 Answers1

0

You use the commands as.character and paste

In your case, something like this would work

x <- c(1:4)
x <- as.character(x)
x <- paste("Region", x)
print(x)
[1] "Region 1" "Region 2" "Region 3" "Region 4"

Although I think R overloads its functions sufficiently so that this would work without first converting x to a character, as noted by the comment above. I included the as.character bit because the OP asked "does anyone know how to do the convert numeric value into string value in R".

  • Oh, thank you very much. I need to run a Levene test but R always refused to execute and returned a warning that this is not possible for quantitative explanatory variables. When I used excel to do the conversion I asked before running the test, it ran smoothly. But I need to submit R code to my teacher, so your suggestion is perfect :D –  Jan 09 '17 at 05:57
  • For that you could also convert `x` to a factor by using `as.factor` –  Jan 09 '17 at 06:00