我想将多个值从一个数据框映射到另一个数据框。一个变量就足够简单了:
foods <- data.frame("name"=c("beef","soy","water","beef"))
data <- data.frame("name"=c("beef","soy","water"),"a"=c(1,2,3),"b"=c(4,5,6),"c"=c(0,0,0))
library(plyr)
foods$a <- mapvalues(foods$name, data$name, data$a)
但是我如何遍历df“数据”的多列而又不必为每个变量重写同一行
foods$b <- mapvalues(foods$name, data$name, data$b)
一个循环?聪明?