我在Excel中使用了很多vlookup公式,我嘗試使用data.table包在R中進行轉置。使用R在列中匹配值 - excel vlookup
在我下面的例子中,我要說,對於每一行,找到列x
中的列y
中的值,並返回列z
中的值。
第一行的結果爲na
,因爲值6
在列x
中不存在。
在第二行的值5
出現在x
柱兩次,但返回的第一場比賽是好的,這是在這種情況下
我在結果列這是預期結果添加e
。
library(data.table)
dt <- data.table(x = c(1,2,3,4,5,5),
y = c(6,5,4,3,2,1),
z = c("a", "b", "c", "d", "e", "f"),
Result = c("na", "e", "d", "c", "b", "a"))
非常感謝
http://stackoverflow.com/questions/18645222/vlookup-type-method-in-r,http://stackoverflow.com/questions/15303283/how-to-do-vlookup-and-fill-down -like-in-excel-in- – jogo