June 2017
Beginner to intermediate
576 pages
15h 22m
English
Often the first and last word of product descriptions contain useful information, and sometimes you can use a single word or phrase in place of the original longer description. This may not always be the case, but it is worth trying. In order to extract the last word from the descriptions, we can use the word function from the stringr package:
library(stringr)OnlineRetail$lastword <- word(OnlineRetail$Description, -1) #supply -1 to extract the last wordOnlineRetail$Description <- trimws(OnlineRetail$Description, "l")OnlineRetail$firstword <- word(OnlineRetail$Description, 1)# use head(OnlineRetail) if you are no using Rmarkdownkable(OnlineRetail[1:5, c(3, 10:12)], padding = 0)
Firstword appears as the last column ...