Denise
Denise

Reputation: 3

How do you convert a variable from an integer to a string in base R?

I've just started using R and I have no aptitude for coding. I don't speak the language so I can't follow the examples I've seen (sorry!).

I have a variable called Gender which has levels 1 and 2, which I created like this:

factor(Gender, levels = c(1,2), labels = c("Male","Female"))

It appears that the 1's and 2's for the variable are registering as "integers" but I want them to be registered as string variables (ie nominal values).

How do I tell R to change 1 and 2 to "1" and "2", please?

Upvotes: 0

Views: 2258

Answers (1)

Daniel O
Daniel O

Reputation: 4358

you can use as.character(...) to treat objects as character strings.

Upvotes: 2

Related Questions