return string of values of vector based on level in R

1k views Asked by At

Sorry if this is a basic question, i'm very new to R.

Say I have a vector with certain values with these levels:

x=c(3,1,2,1)
levels(x)[c(1,2,3)]=c("Coins","Mix", "Liquid")

How can I return a vector of x with the values of the level as a string (e.g. "Liquid", "Coins", "Mix", "Coins").

Thanks

1

There are 1 answers

2
jeremycg On BEST ANSWER

This is a weird way to format data, but here's an answer:

levels(x)[x]