Difference between revisions of "R: sentiments analysis"

From OnnoWiki
Jump to navigation Jump to search
Line 16: Line 16:
 
  tidy_books <- austen_books() %>%
 
  tidy_books <- austen_books() %>%
 
     group_by(book) %>%
 
     group_by(book) %>%
        mutate(linenumber = row_number(),
+
    mutate(linenumber = row_number(),
              chapter = cumsum(str_detect(text, regex("^chapter [\\divxlc]",
+
            chapter = cumsum(str_detect(text, regex("^chapter [\\divxlc]",
              ignore_case = TRUE)))) %>%
+
            ignore_case = TRUE)))) %>%
              ungroup() %>%
+
            ungroup() %>%
        unnest_tokens(word, text)
+
    unnest_tokens(word, text)
 +
 
 +
 
 +
 
 +
 
  
 
==Pranala Menarik==
 
==Pranala Menarik==
  
 
* [[R]]
 
* [[R]]

Revision as of 16:57, 8 November 2018


library(tidytext)
sentiments


get_sentiments("afinn")
get_sentiments("bing")
get_sentiments("nrc")


library(janeaustenr)
library(dplyr)
library(stringr)
tidy_books <- austen_books() %>%
    group_by(book) %>%
    mutate(linenumber = row_number(),
           chapter = cumsum(str_detect(text, regex("^chapter [\\divxlc]",
           ignore_case = TRUE)))) %>%
           ungroup() %>%
    unnest_tokens(word, text)



Pranala Menarik