R - Replace multiple patterns with multiple ids

后端 未结 1 909
栀梦
栀梦 2021-01-28 07:27

This was partially already tackled in others posts but unfortunately I could not make it run properly on my side.

I have a data frame full of texts, and there are certain

相关标签:
1条回答
  • 2021-01-28 07:54

    You can create a named list and use it to replace values in str_replace_all :

    hous$HouseType <- stringr::str_replace_all(hous$HouseType, 
                                setNames(maps$UniqueID, maps$Names))
    hous
    
    #                HouseType               HouseTypeNo
    #1 Fruit Fruit Fruit Honey Onion Garlic Pepper Sugar
    #2 Animals Animals Animals       Mushrooms Soya Eggs
    
    0 讨论(0)
提交回复
热议问题