将列值映射到整数

时间:2016-10-13 14:30:17

标签: r

我有一个数据框,我在R中加载,看起来像这样:

id    binary_value    multivalued_attribute1    multivalued_attribute2
0     0               value11                   value22
1     0               value15                   value24
2     0               value11                   value22
3     1               value14                   value22

二进制值是一个简单的yes or no问题,而value1xvalue2x是字符串值,每个值的值有限。

如何将多值列切换为数字数据,以便绘制热图?因为尝试绘制而那些是字符串需要花费太多时间。

1 个答案:

答案 0 :(得分:0)

怎么样:

dat$multivalued_attribute1 <- as.numeric(factor(dat$multivalued_attribute1))
dat$multivalued_attribute2 <- as.numeric(factor(dat$multivalued_attribute2))

其中dat是您的数据框...