Get characters before first space
Or just sub
, with credit to @flodel:
sub(" .*", "", words)
# and if the 'space' can also be a tab or other white-space:
sub("\\s.*","",words)
#[1] "the" "brown" "lazier"
You can use qdap
's beg2char
(beginning of the string to a particular character) as follows:
x <- c("the quick", "brown dogs were", "lazier than quick foxes")
library(qdap)
beg2char(x)
## [1] "the" "brown" "lazier"