使用 Quanteda.textstats 时出现错误“选择了未定义的列”

问题描述 投票:0回答:1

我正在运行一个主题模型项目,并在制作实际模型之前使用

quanteda
quanteda.textstats
查看二元组。当我尝试
tokens_compound
时,我收到错误:

Error in `[.data.frame`(col, col$z > 1) : undefined columns selected
.

但是,我知道

z
列存在,z > 1 中存在值,并且我正在使用我知道绝对有效的其他人的代码。下面是我使用的代码。我使用
janeausten
包来简化重现性;我对该数据集也遇到了同样的错误。

library(janeaustenr)
library(tidyverse)
library(quanteda)
library(quanteda.textstats)

data(sensesensibility)

sensesensibility <- as.data.frame(sensesensibility)

##add id column to the data frame
sensesensibility <- sensesensibility %>% 
  mutate(id = row_number()) %>% 
  slice(13:30) ##first few lines aren't full lines of text

corpus <- corpus(sensesensibility,
                     docid_field = "id",
                     text_field = "sensesensibility")



tokens <- corpus %>%
  tokens(remove_punct = TRUE, 
         remove_numbers = TRUE, 
         remove_symbols = TRUE, 
         remove_separators = TRUE) %>%
  tokens_tolower()

##see if it worked (it did)
tokens

col <- textstat_collocations(tokens, size = 2)

tokens.col <- tokens_compound(tokens, pattern = col[col$z > 1], concatenator = "_")

r quanteda
1个回答
0
投票

col
是一个二维对象,我们对它的过度分类更喜欢二维索引。

所以这有效:

tokens.col <- tokens_compound(tokens, 
                              pattern = col[col$z > 1, ],
                              concatenator = "_")
© www.soinside.com 2019 - 2024. All rights reserved.