Converting letters to numbers in entire dataframe

后端 未结 4 984
攒了一身酷
攒了一身酷 2020-12-21 01:40

I am having trouble applying the chartr() function on all columns of my data frame for converting letters to numbers.

I managed doing it on single colum

4条回答
  •  悲&欢浪女
    2020-12-21 02:05

    > cbind(DF, setNames( lapply( DF[-1], chartr, old='ACGT', new='1234'), 
                          paste0("POS", 1:(length(DF)-1),"X"))  )
      ID POS1 POS2 POS3 POS1X POS2X POS3X
    1  1   AG   GT   GG    13    34    33
    2  2   GC   CC   CT    32    22    24
    3  3   TT   TC   AT    44    42    14
    

提交回复
热议问题