Hi,
I would like to remove last word from the column "Category" where country is "CA" in this example below.
I have been using separate() for a while, but in this case separate doesn't help as the number of words in a column can vary and I just want to remove the last one.
Another option is to remove words containing "WORD" or "TXT"
Is it possible? I am looking to learn both of these options.
Thanks for your help!
library(tidyverse)
library(datapasta)
# Example data
df <- data.frame(
stringsAsFactors = FALSE,
Country = c("USA","USA","USA","USA",
"USA","CA","CA","CA","CA","CA","CA","CA","CA",
"CA","CA","USA","USA","USA","CA","CA","CA",
"CA","CA"),
Category = c("Soft Goods RU",
"Soft Goods TXT1","Soft Goods TXT2","Hard Goods TXT3",
"Hard Goods TXT4","Hard Goods WORD1","Hard Goods WORD2",
"Hard Goods WORD3","Hard Goods ABC WORD12",
"Hard Goods XYZ ABC LMN WORD1","Hard Goods","Hard Goods",
"Hard Goods","Hard Goods","Hard Goods","Soft Goods WORD",
"Soft Goods WORD1","Soft Goods","Hard Goods",
"Hard Goods","Hard Goods","Hard Goods","Hard Goods")
)