我有 2 个数据集具有相同的列和不同的行数。
> dput(smalldf)
structure(list(X = structure(1:5, .Label = c("A", "B", "C", "F",
"G"), class = "factor"), Y = c(1L, 2L, 3L, 6L, 7L), Z = c(10L,
20L, 30L, 60L, 70L)), .Names = c("X", "Y", "Z"), class = "data.frame", row.names = c(NA,
-5L))
> dput(bigdf)
structure(list(X = structure(1:7, .Label = c("A", "B", "C", "D",
"E", "F", "G"), class = "factor"), Y = c(10L, 20L, 30L, 40L,
50L, 60L, 70L), Z = c(100L, 200L, 300L, 400L, 500L, 600L, 700L
)), .Names = c("X", "Y", "Z"), class = "data.frame", row.names = c(NA,
-7L))
我想匹配相似的行并减去 Y 列。我知道这是一项非常简单的任务,但我无法做到!我应该使用match()
吗?还是这里的某种apply()
功能?