I have the following data frame dat :
brand (column name)
Channel clothes
Gucci perfume
Channel shoes
LV purses
LV scarves
我希望创建一个新列,只包含品牌名称,即无论后面跟着什么,都是列"brand"的第一个单词。我希望输出如下:
brand (column name)
Channel
Gucci
Channel
LV
LV
我尝试使用下面的代码来调用子程序,但它无法工作。请问我的代码有什么问题?
brand <- sub("(\\w+).*", "\\1", dat$brand)
sub(" .*$", "", dat$brand)
去除第一个空格后的所有内容。 - lmo?stringi::stri_extract_first_words
- hrbrmstr