使用revalue()为data.frame列中的字符分配数字时出错

时间:2019-03-05 23:39:12

标签: r

我正在使用plyr包中的revalue()将数字值分配给带有字符的向量,因此可以使用ggplot对其进行图形绘制。 到目前为止,我已经尝试过:

library(plyr)
x$avy_danger <- revalue(x$avy_danger, c("Low"="1", "Moderate"="2", "Considerable"="3", "High"="4"))

但出现此错误:

The following `from` values were not present in `x`: Low, Moderate, Considerable, High

尽管我的向量包含这些以及data.frame,如在以下示例中所示:

 x$avy_danger
 [1] Considerable  Considerable  Low           Low           Low           Low           Moderate      Moderate      Considerable 
[10] Considerable  Moderate      Considerable  Considerable  Moderate      Moderate      Moderate      Moderate 



 x
     Date  HN24 HN24W.SWE. Density....   HST Total Air.T T.Max T.Min       Sky           Precip    avy_danger
1  2019-03-05  4.00       1.60        0.06 11.00   230 -20.0  -3.5 -20.0 Scattered No precipitation Considerable 
2  2019-03-04  5.00       4.30        0.11    NA   228  -8.5  -6.5 -12.0  Overcast             Snow Considerable 

我希望能够根据我为其分配的值来绘制avy_danger。谢谢。

0 个答案:

没有答案