Extract text after a symbol in R

Looper picture Looper · May 5, 2016 · Viewed 22.1k times · Source
sample1 = read.csv("pirate.csv")
sample1[,7] 
[1] >>xyz>>hello>>mate 1
[2] >>xyz>>hello>>mate 2
[3] >>xyz>>mate 3
[4] >>xyz>>mate 4
[5] >>xyz>>hello>>mate 5
[6] >>xyz>>hello>>mate 6

I have to extract and create an array which contains all the words after last >>.

How to do this?

Also, How can I extract (a) o qwerty, (b) mate1 and (c) pirate1 in different variables from the following string

p= '>>xyz- o qwerty>>hello>>mate1>>sole pirate1'

Thanks

Answer

Sotos picture Sotos · May 5, 2016
x <- c('>>xyz>>hello>>mate 1', '>>xyz>>hello>>mate 2', '>>xyz>>mate 3', ' >>xyz>>mate 4' ,'>>xyz>>hello>>mate 5')
sub('.*>>', '', x)
#[1] "mate 1" "mate 2" "mate 3" "mate 4" "mate 5"