Loops - create a random string and add to a data frame

stupid copy / paste error, sorry about that! (code below modified from this thread)

install.packages(c("janeaustenr","tidytext"))

library(janeaustenr)
library(dplyr)
library(stringr)
library(tidytext)

original_books <- austen_books() %>%
  group_by(book) %>%
  mutate(linenumber = row_number(),
         chapter = cumsum(str_detect(text, regex("^chapter [\\divxlc]",
                                                 ignore_case = TRUE)))) %>%
  ungroup()

tidy_books <- original_books %>%   unnest_tokens(word, text)
words <- tidy_books$word
sdata <- sample(words[1:15], size = sample(1:15), replace = TRUE)
paste(sdata, sep=' ', collapse=' ')

1 Like