We are moving data from an old ERP system to a new one, the new one limits the description of items to 50 words, while the older one had no such limit. How can I ask R to remove the words at the end of the string if they are more than 50?
Edit: The suggested solution is giving me a description column 50 words each, however, when the words are lesser than 50, it is putting NA in place of words till it makes 50 words. Plust the part that was removed is not stored anywhere.
I used word_count in qdap package to count the number of words and inserted the new variable into the original dataframe. Now how can I use this column to remove all words after 50th word (if number of words>50)? I am thinking of using a word position where count>50? I'd like to put the extra words into another existing column called 'extended description'.
data[,c("wordcount")]<-wc(data$Description,digit.remove = FALSE)
Input data: Separator && here only, (actually a data frame in R)
Description && wordcount && Ext Desc
MARY, EWARD-PURE FOR 12 QT HOP && 6 &&
MARY, HARRY FILTER, 1 TO 3 IN SIZE, LARGE && 10 && xxxxxx
MARY, ORGAN, MAXI WHEEL, TP F-SHAPED && 6 &&
MARY, COMBINATION DEBATABLE, 10 IN ….. && 56
Data Picture