如何使用其他值替换数据框中的值

时间:2015-06-09 15:14:42

标签: r dataframe

我有庞大的数据集。列包含A,B,C,D,E,F,G,H等值,我需要将其替换为1,2,3,4...

[1] "C" "C" "C" "C" "C" "A" "H" "G" "G" "G" "G" "G" "G" "G" "C" "C" "C" "C" "C"
[20] "C" "B" "B" "B" "H" "H" "H" "H" "H" "H" "G" "C" "A" "A" "A" "A" "A" "A" "A"
[30]----

另一个类似的问题是,一列中的值超过1000,我需要用唯一的数字替换它们。

1 个答案:

答案 0 :(得分:0)

尝试replace

replace function examples

在你的情况下,例如

replace(df, "A", 1)