code for converting numerical to character

Hi there,

what are the codes to convert a numerical variable to a character variable or inverse in a known dataset?

Thanks,
Jason

Have you tried as.character() or as.numeric()?

I did try as.character, but didn't go through. the variable 'Sex' in data 'final' is numerical, the codes I used

final1 <-final %>%
as.character(Sex)

Thanks, both work well.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

It's hard to help without a reprex or some data at least. Please look at the FAQ.

It probably fails because final is a data frame and you should use as.character for a vector; either directly or using mutate() from the dplyr package.

final1 <- final
final1$Sex <- as.character(final1$Sex)
# Or: final1 <- final %>% mutate(Sex = as.character(Sex))

Almost there:

final1 <- final %>%
  mutate(Sex = as.character(Sex))