Dictionary style replace multiple items

前端 未结 10 766
太阳男子
太阳男子 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条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 05:27

    Here is a quick solution

    dict = list(AA = '0101', AC = '0102', AG = '0103')
    foo2 = foo
    for (i in 1:3){foo2 <- replace(foo2, foo2 == names(dict[i]), dict[i])}
    

提交回复
热议问题