【发布时间】:2021-09-25 18:34:16
【问题描述】:
我正在尝试为以下 df 执行 bind_tf_idf()。我的 df 有两个文档/类:Y 或 N。
> test_2
# A tibble: 3,295 x 2
Class word
<fct> <chr>
1 Y nature
2 Y great
3 Y are
4 Y present
5 N in
6 N weather
7 Y moisture
8 N humidity
9 Y and
10 Y pollen
# … with 3,285 more rows
Warning message:
`...` is not empty.
We detected these problematic arguments:
* `needs_dots`
These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
这是我正在使用的:
test_2_tf_idf <- test_2 %>%
bind_tf_idf(word, Class, sum)
但我收到错误消息:
> test_2_tf_idf <- test_2 %>%
+ bind_tf_idf(word, Class, sum)
'Error in tapply(n, documents, sum) : arguments must have same length'
我最终想要的是一个类似于此的计算表(忽略“总计”列):
#> # A tibble: 40,379 x 7
#> book word n total tf idf tf_idf
#> <fct> <chr> <int> <int> <dbl> <dbl> <dbl>
#> 1 Mansfield Park the 6206 160460 0.0387 0 0
#> 2 Mansfield Park to 5475 160460 0.0341 0 0
#> 3 Mansfield Park and 5438 160460 0.0339 0 0
#> 4 Emma to 5239 160996 0.0325 0 0
#> 5 Emma the 5201 160996 0.0323 0 0
#> 6 Emma and 4896 160996 0.0304 0 0
#> 7 Mansfield Park of 4778 160460 0.0298 0 0
#> 8 Pride & Prejudice the 4331 122204 0.0354 0 0
#> 9 Emma of 4291 160996 0.0267 0 0
#> 10 Pride & Prejudice to 4162 122204 0.0341 0 0
#> # … with 40,369 more rows
除了在我的情况下,“书”列类似于每个单词的“Y”或“N”类。
我可以做些什么来修复这个 tapply 错误?
【问题讨论】: