Irakli
January 18, 2021, 7:10pm
1
I'm sorry, but I couldn't get reprex.
I have many character columns with numbers and characters. I want to remove characters and leave numbers but to do this with many variables at the same time.
I am using this code:
pandemic_siordia %>%
mutate(across(anxiety_1:lifesat_5), str_extract("^\d+"))
with different modifications (changing variables, or putting ".," in str_extract) but still get various errors.
What can I possibly be doing wrong?
FJCC
January 18, 2021, 7:37pm
2
I cannot test this at the moment but try putting str_extract() inside of the across function.
pandemic_siordia %>%
mutate(across(.cols = anxiety_1:lifesat_5, .fns = str_extract, pattern = "^\d+"))
1 Like
Irakli
January 18, 2021, 8:12pm
4
Thank you very much. It worked! You have helped me on the last three questions, I don't know how to thank you.
ali4R
January 18, 2021, 10:26pm
5
you can try gsub() for removing characters from a given string.
1 Like
system
Closed
January 25, 2021, 10:26pm
6
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.