【发布时间】:2018-11-08 11:04:00
【问题描述】:
所以我正在为我的推文研究建立一个框架。我的部分框架包括构建最终数据集,以供以后用于分类和主题建模目的。
我有三个对象:
1.) ngram.features.df - 包含 44159 行/推文,3 列,即 ID、X1 和 X2
2.) tweets.corpus - 从 ngram.features.df 列 X1 创建的语料库,X1 包含用于处理的已清理推文
3.) mydtm - 是一个文档术语矩阵,减少到 44043 行/推文,因为我已经消除了 doc.lengths = 0 的行/推文。这是通过:doc.lengths <- rowSums(as.matrix(DocumentTermMatrix(tweets.corpus)))
mydtm <- DocumentTermMatrix(tweets.corpus[doc.lengths > 0], control = list(wordLengths = c(3,10)))
> mydtm
<<DocumentTermMatrix (documents: 44043, terms: 9252)>>
Non-/sparse entries: 325412/407160424
Sparsity : 100%
Maximal term length: 10
Weighting : term frequency (tf)
如您所见,mydtm 减少到 44043 行,而我的原始数据框 ngram.features.df 构建 mydtm 的地方有 44159 行。
现在,我无法将原始文档/推文的 ID's 从数据框中保留到 mydtm 中。
我尝试了How can I manually set the document id in a corpus? 中的那个,但它与不在 DTM 上的语料库中设置 ID 有关。
现在问题在于merge。我将mergengram.features.df(44159)使用mydtm(44043)的数据框版本。但是,由于减少,他们在此处的行数/推文/文档数会不一致。因此,需要保留 ID。
谁能提供帮助?
【问题讨论】: