Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text to lowercase in R keeping acronyms in uppercase in text mining

Tags:

r

How can I change a full text to lowercase but retain the acronyms in uppercase using R? I need it for text mining and using udpi package. I could ofcourse use uppercase, but anyway to retain the uppercase acronyms while using lowercase?

tolower('NASA IS A US COMPANY').

tolower('NASA IS A US COMPANY')
tolower('NASA IS A US COMPANY')

Expected: NASA is a US company

Actual: nasa is a us company
like image 745
Dejie Avatar asked Jan 20 '26 03:01

Dejie


1 Answers

We can do: test is the input:

paste(lapply(strsplit(test," "),function(x) ifelse(x %in% toupper(tm::stopwords()),
                                              tolower(x),x))[[1]],collapse=" ")
[1] "NASA is a US COMPANY"
like image 152
NelsonGon Avatar answered Jan 22 '26 21:01

NelsonGon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!