My piece of code to remove short & long words from some text is:
# Remove Words based on lowerCutOff & upperCutOff
removeByLength<- function(text,lowerCutOff=2,upperCutOff=12){
text<- gsub("\\b[a-zA-Z0-9]{1,lowerCutOff}\\b|\\b[a-zA-Z0-9]{upperCutOff,}\\b"," ",text)
return(text)
}
How can I achieve the needed functionality without hardcoding the lower & upper cutoffs?
Use
pasteto concatenate the strings to create the pattern: