How can I remove punctuations and numbers in text from data.frame file in R

Clash Royale CLAN TAG#URR8PPPHow can I remove punctuations and numbers in text from data.frame file in R
I want to remove punctuations, numbers and http links in text from data.frame file. I tried tm, stringr, quanteda, tidytext packages but none of them worked. I m looking for a useful basic package or function for clean data.frame file without convert it to corpus or something like that.
How can I do it?
Welcome to SO. it is always recommended to post samples of Input and expected output in your post with code tags.
– RavinderSingh13
21 mins ago
1 Answer
1
Since you haven't posted any sample input or sample output so couldn't test it, for removing punctuation, digits and http links from your data frame's specific column you could try following once.
gsub("[[:punct:]]|[[:digit:]]|^http:\/\/.*|^https:\/\/.*","",df$column)
OR as per Rui's suggestion in comments use following too.
gsub("[[:punct:]]|[[:digit:]]|(http[[:alpha:]]*:\/\/","",df$column)
Nice try but it doesn't remove
http: because it can have an s before the colon. I've used "[[:punct:]]|[[:digit:]]|(http[[:alpha:]]*:\/\/)".– Rui Barradas
10 mins ago
http:
s
"[[:punct:]]|[[:digit:]]|(http[[:alpha:]]*:\/\/)"
My test string was this question's web address.
– Rui Barradas
9 mins ago
@RuiBarradas, cool sure thanks for letting know, changed it now/.
– RavinderSingh13
6 mins ago
@RuiBarradas, added your suggestion too now with credit, cheers buddy.
– RavinderSingh13
5 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What exactly have you tried? Please see here on making an R post we can help with. That includes a representative sample of data, code that hasn't worked, and expected output.
– camille
28 mins ago