【发布时间】:2018-02-05 18:13:12
【问题描述】:
我正在编写一个代码,其中列名(例如"Category")由用户提供并分配给变量biz.area。比如……
biz.area <- "Category"
原始数据框保存为risk.data。用户还通过为变量first.column 和last.column 提供列名来提供要分析的列范围。
这些列中的文本将被分解为二元组,以进行进一步的文本分析,包括 tf_idf。
我的分析代码如下。
x.bigrams <- risk.data %>%
gather(fields, alldata, first.column:last.column) %>%
unnest_tokens(bigrams,alldata,token = "ngrams", n=2) %>%
count(bigrams, biz.area, sort=TRUE) %>%
bind_tf_idf(bigrams, biz.area, n) %>%
arrange(desc(tf_idf))
但是,我收到以下错误。
grouped_df_impl(data, unname(vars), drop) 中的错误:列
x.biz.area未知
这是因为count() 需要一个列名文本字符串,而不是变量biz.area。如果我改用count_(),我会收到以下错误。
compat_lazy_dots(vars, caller_env()) 中的错误:对象 'bigrams' 没找到
这是因为count_() 只希望找到变量,而bigrams 不是变量。
如何将常量和变量同时传递给count() 或count_()?
感谢您的建议!
【问题讨论】:
-
您能否提供一些示例数据(使用
dput()等)以及您想要作为最终输出的内容?