return 基于 R 中级别的矢量值字符串

return string of values of vector based on level in R

抱歉,如果这是一个基本问题,我是 R 的新手。

假设我有一个具有这些级别的特定值的向量:

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

我如何 return 一个 x 的向量,其中级别的值作为字符串(例如 "Liquid"、"Coins"、"Mix"、 "Coins")。

谢谢

这是一种奇怪的数据格式化方式,但这里有一个答案:

levels(x)[x]