【发布时间】:2016-05-15 08:27:36
【问题描述】:
我的出发点是有几个包含我从文本中提取的 POS 标签的字符向量。例如:
c("NNS", "VBP", "JJ", "CC", "DT")
c("NNS", "PRP", "JJ", "RB", "VB")
我使用table() 或ftable() 来计算每个标签的出现次数。
CC DT JJ NNS VBP
1 1 1 1 1
最终目标是让 data.frame 看起来像这样:
NNS VBP PRP JJ CC RB DT VB
1 1 1 0 1 1 0 1 0
2 1 0 1 1 0 1 0 1
在这里使用plyr::rbind.fill 对我来说似乎是合理的,但它需要 data.frame 对象作为输入。但是,当使用as.data.frame.matrix(table(POS_vector)) 时会发生错误。
Error in seq_len(ncols) :
argument must be coercible to non-negative integer
使用as.data.frame.matrix(ftable(POS_vector)) 实际上会生成一个data.frame,但没有colnames。
V1 V2 V3 V4 V5 ...
1 1 1 1 1
非常感谢任何帮助。
【问题讨论】:
标签: r dataframe contingency