Dictionary style replace multiple items

前端 未结 10 621
太阳男子
太阳男子 2020-11-22 05:02

I have a large data.frame of character data that I want to convert based on what is commonly called a dictionary in other languages.

Currently I am going about it li

10条回答
  •  -上瘾入骨i
    2020-11-22 05:24

    If you're open to using packages, plyr is a very popular one and has this handy mapvalues() function that will do just what you're looking for:

    foo <- mapvalues(foo, from=c("AA", "AC", "AG"), to=c("0101", "0102", "0103"))
    

    Note that it works for data types of all kinds, not just strings.

提交回复
热议问题