0

I am trying to conduct text analytics using tm package in r. I am on a windows system.

I have created a simple function to convert the plural nouns into single format. please see attached for the code.

to_single<-function(x){
if(str_sub(x,-3)=="ies"){
str_sub(x,-3)<-"y"}
else if(str_sub(x,-2)=="es"){
str_sub(x,-2)<-""
}
else if(str_sub(x,-1)=="s"){
str_sub(x,-1)<-""}
else{
x=x}
return(x)
}

Then I try to use the content_transformer and tm_map function to clean the corpus created.

to_Single <- content_transformer(to_single)
docs <- tm_map(docs, to_Single)

#docs is the corpus I created.

However this does not work. Can anyone let me know where am I wrong?

Thanks so much for your kind help.

aalen
  • 21
  • 4
  • 2
    Please provide a reproducible example data set. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Pierre Lapointe Jun 26 '17 at 19:57
  • What do you mean by "does not work" exactly? Are you getting an error? If so, be sure to include that. Be sure to include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can test and verify possible solutions (it doesn't have to be your real data, just something to test with). Also be sure to include the version number of the `tm` library that you are using from `sessionInfo()`. – MrFlick Jun 26 '17 at 20:00

0 Answers0