Trying to find a way to return the first three words in R. I tried the word function in string_r but it only returns the first three words if the sentence has at least three words. e.g.,
sentences <- c("Jane saw a cat", "Jane sat down", "Jane sat", "Jane")
word(sentences, 1, 3)
This returns Jane saw a, Jane sat down, NA, NA
I would like it to return the first three words, even if the sentence has one or two words. So the output I am looking for is:
This returns Jane saw a, Jane sat down, Jane Sat, Jane