[Solved] R: How can I change a matrix array? [closed]


Many options here. Unfortunately you don’t show any effort to resolve the problem or even to make it clear and reproducible. For example, using ifelse :

dat <- read.table(text=""aaa" 28
                  "aac" 8
                  "aag" 20")
dat$V1 <- with(dat,ifelse(V1 %in% c('aaa','aag'),'K','N'))
dat
  V1 V2
1  K 28
2  N  8
3  K 20

EDIT
If I want to replace “aaa” with “K”, “aac” with “N” and “aag” with “G”:

dat$V1 <- with(dat,ifelse(V1 == 'aaa',
                          'K',
                          ifelse(V1=='aac','N','G')))
 dat
  V1 V2
1  K 28
2  N  8
3  G 20

2

solved R: How can I change a matrix array? [closed]