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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -