首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用tidytext以txt格式实现令牌化

使用tidytext以txt格式实现令牌化
EN

Stack Overflow用户
提问于 2018-05-10 22:07:31
回答 2查看 253关注 0票数 0

我试图使用名为:.txt文件的tidytext来处理tidytext,其结构如下:

代码语言:javascript
复制
# A tibble: 254 x 230
   X1     X2     X3     X4    X5    X6    X7    X8    X9    X10   X11   X12   X13   X14   X15   X16  
   <chr>  <chr>  <chr>  <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
 1 la     expro~ de     la    tier~ ocur~ con   frec~ dura~ el    proc~ rapi~ de    la    urba~ en   
 2 como   las    difer~ en    el    moti~ del   cons~ cons~ en    esta~ unid~ y     china afec~ la   
 3 las    desig~ etnic~ en    los   patr~ de    cons~ (pre~ de    vest~ joye~ auto~ han   sido  obje~
 4 este   artic~ exami~ el    impa~ de    vari~ dife~ indi~ en    la    prop~ de    los   cons~ a    
 5 este   artic~ inves~ la    infl~ de    los   regi~ poli~ sobre la    impo~ 
 #   ...

尝试使用unnest_tokens格式时,使用以下代码:

代码语言:javascript
复制
library(tidytext)

texto_revision %>%
    unnest_tokens(word, text)

我得到以下错误:

错误: check_input(x)中的错误:输入必须是任意长度的字符向量或字符向量列表,每个字符向量的长度为1。

为了纠正错误并继续前面的标记化,我尝试用以下代码将文本转换为数据帧:

代码语言:javascript
复制
text_df <- as.data.frame(texto_revision)

但我仍然得到以下错误

check_input(x)中的错误:输入必须是任意长度的字符向量或字符向量列表,每个字符向量的长度为1。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-05-11 01:11:27

注意,unnest_tokens的语法是“unnest_tokens(新列名引用列”)。在Ti球/数据框架中似乎没有“文本”列。下面是一个玩具示例,以说明:

代码语言:javascript
复制
State <- as.character(c("SC is in the South","NC is in the south", 
                        "NY is in  the north"))
DF <- data.frame(State, stringsAsFactors = FALSE)

> DF
               State
 1 SC is in the South
 2 NC is in the south
 .....
 DF %>% unnest_tokens(word,State)

     word
1      sc
1.1    is
1.2    in
1.3   the
....
票数 0
EN

Stack Overflow用户

发布于 2018-05-11 03:45:03

看起来您的文本已经被标记为,所以您只需要熔化数据帧就可以得到想要的数据结构。例如,

代码语言:javascript
复制
library(tidyverse)

texto_revision %>%
  gather(document, word)

参见文档 for tidyr::gather()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50282173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档