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.