How to do vlookup and fill down (like in Excel) in R?

前端 未结 8 702
悲&欢浪女
悲&欢浪女 2020-11-22 11:25

I have a dataset about 105000 rows and 30 columns. I have a categorical variable that I would like to assign it to a number. In Excel, I would probably do something with

8条回答
  •  不思量自难忘°
    2020-11-22 11:56

    I think you can also use match():

    largetable$HouseTypeNo <- with(lookup,
                         HouseTypeNo[match(largetable$HouseType,
                                           HouseType)])
    

    This still works if I scramble the order of lookup.

提交回复
热议问题