无法将类“功能”强制转换为data.frame

时间:2019-05-10 07:39:06

标签: r powerbi

我正在用R脚本编写的power BI中实现比较云,但似乎出现错误

Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  cannot coerce class '"function"' to a data.frame
Calls: data.frame -> as.data.frame -> as.data.frame.default

我试图在RStudio中运行它,并且效果很好。

#Subsection
  pol_subsections <- function(df) {
    x.pos <- subset(df$text, df$polarity > 0)
    x.neg <- subset(df$text, df$polarity < 0)
    x.pos <- paste(x.pos, collapse = " ")
    x.neg <- paste(x.neg, collapse = " ")
    all.terms <- c(x.pos, x.neg)
    return(all.terms)
  } 

all_tdm <- dataset %>%
    select( text = text.var, polarity = polarity) %>%
    pol_subsections() %>%
    VectorSource() %>%
    VCorpus() %>%
    TermDocumentMatrix(
        control = list(
            removePunctuation = TRUE,
            stopwords = stopwords(kind = "en")
        )
    ) %>%
    as.matrix() %>%
    set_colnames(c("positive", "negative"))

comparison.cloud(all_tdm, max.words = 40, colors = c("darkgreen", "darkred"))

这是我的数据集:

head(dataset)
  my_data.all wc polarity pos.words neg.words   text.var
1         all  1        0         -         -       able
2         all  1        1  accurate         -   accurate
3         all  1        1 adaptable         -  adaptable
4         all  1        0         -         - additional
5         all  1        0         -         - applicable
6         all  1        1 available         -  available

0 个答案:

没有答案