I think I fixed the troubles in my code. They had to do with underscores used in the past instead of blank spaces.
######Make a repex
dat<- data.frame(word1=c( "will", "like","get", "look", "next", "social",
"cinco de","manufacturer custom", "custom built"), word2=c(" ", " ", " ",
"like","week", "media", "mayo", "built", "painted"), frequency = c( 5153, 5081, 4821,
559, 478,465, 172,171,171 ) )
dat
#Attempt while loop
#Use while loop
whatsnext <- function(phrase){
nwords <-str_count(phrase, pattern=" ")
while (!(phrase %in% dat$word1) & nwords >=1){
#phrase<- less1gram(phrase)
phrase <-str_replace(phrase, "^[^ ]+ ", "")
#print(phrase)
nwords<-str_count(phrase, pattern=" ")
#print(nxtword1(phrase))
answer <-dat %>% filter(word1 == phrase) %>% select(-word1)
print(answer[1:5, 1])
}
}
The console printed this
> whatsnext("It was a custom built")
[1] <NA> <NA> <NA> <NA> <NA>
Levels: built like mayo media painted week
[1] <NA> <NA> <NA> <NA> <NA>
Levels: built like mayo media painted week
[1] painted <NA> <NA> <NA> <NA>
Levels: built like mayo media painted week
>
Why did R print out three times? What do Levels: indicate?
How can I get answer[1:5, 1] ? I wanted it to show up in the Shiny window as text..