【发布时间】:2019-06-13 18:20:45
【问题描述】:
考虑这个有趣的例子
mytib <- tibble(text = c('i can see clearly now',
'the rain is gone'),
myweight = c(1.7, 0.005))
# A tibble: 2 x 2
text myweight
<chr> <dbl>
1 i can see clearly now 1.7
2 the rain is gone 0.005
我知道如何创建一个由docvars myweight 加权的dfm。我进行如下操作:
dftest <- mytib %>%
corpus() %>%
tokens() %>%
dfm()
dftest * mytib$myweight
Document-feature matrix of: 2 documents, 9 features (50.0% sparse).
2 x 9 sparse Matrix of class "dfm"
features
docs i can see clearly now the rain is gone
text1 1.7 1.7 1.7 1.7 1.7 0 0 0 0
text2 0 0 0 0 0 0.005 0.005 0.005 0.005
但是问题是我既不能使用topfeatures 也不能使用colSums。
那么如何对每一列的值求和呢?
> dftest*mytib$myweight %>% Matrix::colSums(.)
Error in base::colSums(x, na.rm = na.rm, dims = dims, ...) :
'x' must be an array of at least two dimensions
谢谢!
【问题讨论】:
-
colSums(dftest * mytib$myweight)为我工作。 -
疯狂的东西。为什么??
标签: r sparse-matrix quanteda