【发布时间】:2019-03-23 02:49:43
【问题描述】:
我有两个数据框,如下所示。当有匹配时,我想用从数据框 2 中获取的相应值替换数据框 1 中的文本(单元格)。我试图在下面举一个简单的例子。 我对 R 的经验有限,但无法立即想到一个简单的解决方案。任何帮助/建议将不胜感激。
input_1 = data.frame(col1 = c("ex1", "ex2", "ex3", "ex4"),
col2 = c("A", "B", "C", "D"),
col3 = c("B", "E", "F", "D"))
input_2 = data.frame(colx = c("A", "B", "C", "D", "E", "F"),
coly = c(1, 2, 3, 4, 5, 6))
output = data.frame(col1 = c("ex1", "ex2", "ex3", "ex4"),
col2 = c(1, 2, 3, 4),
col3 = c(2, 5, 6, 4))
【问题讨论】: