R中实现vlookup功能可分为两种情况:
1.同一数据框(data.frame)中匹配两列变量,并创建新变量
data <- data.frame(x2=c("a","b","c","d","e","f","g","h","i","j"),x3=c(1:10),x4=c("b","c","d","e","f","g","h","i","",""))
data$x5<-data$x3[match(data$x4,data$x2)]
2.匹配两个数据框则使用merge函数
R中实现vlookup功能可分为两种情况:
1.同一数据框(data.frame)中匹配两列变量,并创建新变量
data <- data.frame(x2=c("a","b","c","d","e","f","g","h","i","j"),x3=c(1:10),x4=c("b","c","d","e","f","g","h","i","",""))
data$x5<-data$x3[match(data$x4,data$x2)]
2.匹配两个数据框则使用merge函数