Simple lookup to insert values in an R data frame

后端 未结 4 1163
旧时难觅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:48

    With such a large data set you may want the speed of an environment lookup. You can use the lookup function from the qdapTools package as follows:

    library(qdapTools)
    alldata$market <- lookup(alldata$zip, zipcodes[, 2:1])
    

    Or

    alldata$zip %l% zipcodes[, 2:1]
    

提交回复
热议问题