Fill values in one vector conditioned on values in another vector

前端 未结 2 1788
粉色の甜心
粉色の甜心 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:47

    You want to merge the two data.frames. It's a many-to-one merge.

    0 讨论(0)
  • 2021-01-28 21:50

    One possibility is to use match:

    x$GDP_deflator <- dataDef$GDP_deflator[match(x$Year, dataDef$Year)]
    
    0 讨论(0)
提交回复
热议问题