What\'s the most elegant way to extract the last word in a sentence string?
The sentence does not end with a \".\" Words are seperated by blanks.
sen
x <- 'The quick brown fox'
sub('^.* ([[:alnum:]]+)$', '\\1', x)
That will catch the last string of numbers and characters before then end of the string.
You can also use the regexec and regmatches functions, but I find sub cleaner:
m <- regexec('^.* ([[:alnum:]]+)$', x)
regmatches(x, m)
See ?regex and ?sub for more info.