How to replace specific data (letters or number) by another data (letters if number) in a data frame in R -
i have data frame looks markers on rows , individuals g1:g5
marker g1 g2 g3 g4 g5 p39 gg gg aa aa aa p40 gg aa aa aa tt p41 aa aa cc tt aa p23 tt tt aa aa tt p35 aa aa aa cc aa
i replace unique calls data frame as
aa=1, tt=2, gg=3, cc=4
and save dataframe csv
does have solution problem many
i might misunderstanding want; it?
dt <- data.frame(marker = c('p39', 'p40', 'p41', 'p2370', 'p350'), g1 = c('gg', 'gg', 'aa', 'tt', 'aa'), g2 = c('gg', 'aa', 'aa', 'tt', 'aa'), g3 = c('aa', 'aa', 'cc', 'aa', 'aa'), g4 = c('aa', 'aa', 'tt', 'aa', 'cc'), g5 = c('aa', 'tt', 'aa', 'tt', 'aa'), stringsasfactors = false) dt[dt == 'aa'] <- 1 dt[dt == 'tt'] <- 2 dt[dt == 'gg'] <- 3 dt[dt == 'cc'] <- 4 write.csv(dt, 'filename.csv')
Comments
Post a Comment