Reputation: 25
I have this question tidying up the data. I have a vector called "opponent" like this:
vs. wakeforest
Utah
vs. [9] Los Angelas
Seattle
vs. [11] UNC
at [19] North Carolina
I only want the opponent name, that is:
wakeforest
Utah
Los Angelas
Seattle
UNC
North Carolina
How should I clean it up? Thanks a lot!
Upvotes: 1
Views: 35
Reputation: 886938
We can match characters until the .
or ]
followed by one or more space (\\s+
) and replace it with ''
.
sub('^.*(\\.|\\])\\s+', '', opponent)
#[1] "wakeforest" "Utah" "Los Angelas" "Seattle"
#[5] "UNC" "North Carolina"
opponent <- c('vs. wakeforest', 'Utah',
'vs. [9] Los Angelas', 'Seattle',
'vs. [11] UNC','at [19] North Carolina')
Upvotes: 3