0

Let's say I have this df

df = data.frame(x = c("S112","S222","S232","S113","S103","S104"),
                y = c("S115","S242","S252","S117","S108","S110")
                )

I wish to obtain the following result

     x    y
1 lung lung
2 S222 S242
3 S232 S252
4 lung lung
5 lung lung
6 lung lung

The condition is that : for each value that starts with S11 or S10, I wish it to be converted to the value lung

Anas116
  • 797
  • 2
  • 9
  • 2
    Take a look at the linked posts. Try `df %>% mutate(across(everything(), ~ ifelse(grepl("^S11|^S10", .x), "lung", .x)))` – benson23 Aug 09 '23 at 11:42

0 Answers0