小编Mic*_*ael的帖子

参数的列数不匹配

我使用这个例子对R中的txt文档集合进行情感分析。代码是:

library(tm)
library(tidyverse)
library(tidytext)
library(glue)
library(stringr)
library(dplyr)
library(wordcloud)
require(reshape2)

files <- list.files(inputdir,pattern="*.txt")

GetNrcSentiment <- function(file){

    fileName <- glue(inputdir, file, sep = "")
    fileName <- trimws(fileName)
    fileText <- glue(read_file(fileName))
    fileText <- gsub("\\$", "", fileText) 

    tokens <- data_frame(text = fileText) %>% unnest_tokens(word, text)

    # get the sentiment from the first text: 
    sentiment <- tokens %>%
        inner_join(get_sentiments("nrc")) %>% # pull out only sentiment words
        count(sentiment) %>% # count the # of positive & negative words
        spread(sentiment, n, fill = 0) %>% …
Run Code Online (Sandbox Code Playgroud)

r sentiment-analysis tidyverse tidytext

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

r ×1

sentiment-analysis ×1

tidytext ×1

tidyverse ×1