how to tidy data separated by underscores

Hello Everyone,
I have a quick question on a character vector below
data <- c("A_B", "A_C", "A _D", "D_ C", "C _C", "D_ D")
and I would like to change as follow
data <- c("A_B", "A_C", "A_D", "D_C", "C_C", "D_D")
Thanks for your help!


data <- c("A_B", "A_C", "A _D", "D_ C", "C _C", "D_ D")

str_remove(data, "\\s")
#> [1] "A_B" "A_C" "A_D" "D_C" "C_C" "D_D"

Created on 2021-09-08 by the reprex package (v2.0.1)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.