Dictionary style replace multiple items

前端 未结 10 769
太阳男子
太阳男子 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:42

    Using dplyr::recode:

    library(dplyr)
    
    mutate_all(foo, funs(recode(., "AA" = "0101", "AC" = "0102", "AG" = "0103",
                                .default = NA_character_)))
    
    #   snp1 snp2 snp3
    # 1 0101 0101 
    # 2 0103  
    # 3 0101 0103 
    # 4 0101 0101 
    

提交回复
热议问题