I have the following data frame dat :
brand (column name) Channel clothes Gucci perfume Channel shoes LV purses LV scarves
And I want to cr
This should do it.
dat <- data.frame(Brand = c('Channel clothes', 'Gucci perfume', 'Channel shoes', 'LV purses', 'LV scarves')) brand <- sub('(^\\w+)\\s.+','\\1',dat$Brand) #[1] "Channel" "Gucci" "Channel" "LV" "LV"