0

I have this type od data frame

Data

structure(list(ID = 1:3, WEEK1 = c(1L, 2L, 1L), WEEK2 = c(2L, 
2L, 3L), WEEK3 = c(3L, 3L, 2L)), class = "data.frame", row.names = c(NA, 
-3L))

DF

ID  WEEK1    WEEK2   WEEK3
1   1        2       3
2   2        2       3
3   1        3       2

I would like to change variables like this:

DF

ID  WEEK1    WEEK2   WEEK3
1   A        B       C
2   B        B       C
3   A        C       B

I have tried

DF %>% mutate_all (1="A", 2="B", 3="C")
Tho Vu
  • 1,304
  • 2
  • 8
  • 20
onhalu
  • 735
  • 1
  • 5
  • 17

1 Answers1

2
df %>%
  mutate(across(matches("WEEK"), chartr, old = '123', new =  'ABC'))
Jakub.Novotny
  • 2,912
  • 2
  • 6
  • 21