0

If i have some data like so:

df = data.frame(person = c('jim','john','pam','jim'),
                date =c('2018-01-01','2018-02-01','2018-03-01','2018-04-01'),
                text = c('the lonely engineer','tax season is upon us, engineers, do your taxes!','i am so lonely','rage coding is the best')                  )

and I wanted to understand trending terms by date, how can I go about that?

  xCorp = corpus(df, text_field = 'text')
    x = tokens(xCorp) %>% tokens_remove(
      c(
        stopwords('english'),
        'western digital',
        'wd',
        'nil'),
      padding = T
    ) %>%
      dfm(
        remove_numbers = TRUE,
        remove_punct = TRUE,

        remove_symbols = T,
        concatenator = ' '
      )
  x2 = dfm(x, groups = 'date') 

This would get me part of the way there, but not sure if it's the best way.

Ted Mosby
  • 1,426
  • 1
  • 16
  • 41

1 Answers1

0

Using the tidyverse, I was able to do the following:

 df = df %>% 
        group_by(date) %>%
        unnest_tokens(word,text) %>%
        count(word,sort = T) %>%  
    }
Ted Mosby
  • 1,426
  • 1
  • 16
  • 41