My data frame
>df <- data.frame(Names = c("A", "B", "C"), Total = c("125", "2 500", "1 350"),
> Boys = c("50", "1 500", "350"),
> Girls = c("75", "1 000", "1 000"))
Names Total Boys Girls
1 A 125 50 75
2 B 2 500 1 500 1 000
3 C 1 350 350 1 000
All values are strings. I want to substitute spaces " " to non spaces "" in Total, Boys and Girls. I know about
df %>%
mutate(Total = gsub(" ", "", Total),
Boys = gsub(" ", "", Boys),
Girls = gsub(" ", "", Girls))
But is there a (tidyverse style) way to do this more generally? Something like
df %>% # (This don't work)
mutate(across(c(Total, Boys, Girls), gsub(" ", "", .x)))
I.e. I'm looking for a solution that scales well.
Thanks in advance.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…