Fill values in one vector conditioned on values in another vector

前端 未结 2 1789
粉色の甜心
粉色の甜心 2021-01-28 21:25

I have two data frames with two different dimensions :

1:

head(x)
   Year GDP_deflator
1  1825           NA
2  1826           NA
3  1827           NA
4           


        
2条回答
  •  面向向阳花
    2021-01-28 21:50

    One possibility is to use match:

    x$GDP_deflator <- dataDef$GDP_deflator[match(x$Year, dataDef$Year)]
    

提交回复
热议问题