0
對於數據幀#1列中的每個條目,我想查看該值是否在數據幀#2中,然後從特定數據幀中獲取一個值第二個數據幀的列,否則爲0,如果無法找到它。有沒有辦法使用其中的一個* apply函數呢?下面R:通過索引來自另一個數據幀的值索引第二個數據幀的值
df1 <- data.frame(
key1 = c("A","B","C","E")
)
df2 <- data.frame(
key2 = c("X", "A", "C", "D", "E"),
val2 = as.integer(c('1','2','23','41','99'))
)
#Answer should be a vector like this:
x <- as.integer(c('2','0','23','99'))
謝謝!這將做我所需要的。 – Boost
很高興爲您提供幫助。如果解決了問題,接受答案可以讓人們知道找到了解決方案。 – Barker