Simple lookup to insert values in an R data frame

后端 未结 4 1166
旧时难觅i
旧时难觅i 2021-02-07 16:14

This is a seemingly simple R question, but I don\'t see an exact answer here. I have a data frame (alldata) that looks like this:

Case     zip     market
1              


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 16:51

    Since you don't care about the market column in alldata, you can first strip it off using and merge the columns in alldata and zipcodes based on the zip column using merge:

    merge(alldata[, c("Case", "zip")], zipcodes, by="zip")
    

    The by parameter specifies the key criteria, so if you have a compound key, you could do something like by=c("zip", "otherfield").

提交回复
热议问题