【发布时间】:2019-04-23 15:04:25
【问题描述】:
我有一个如下所示的数据集:
s <- c("car, car, car, toy, toy", "toy", "horse, horse", "car, horse")
如果我grep("car", s) 我将能够得到[1] 1 4
如果我想得到频率,我可以length(grep("car", s))
但是,我想知道是否有可能得到一个结果,该结果也会返回元素内和元素之间的模式频率?
例如预期结果将类似于以下内容:
[1] 1 1 1 4
和/或
$`car, car, car, toy, toy`
[1] 3
$toy
[1] 0
$`horse, hores`
[1] 0
$`car, horse`
[1] 1
和/或
$`car, car, car, toy, toy`
[1] 3
$`car, horse`
[1] 1
和/或
[[1]]
[1] 3
[[4]]
[1] 1
感谢您的回答。非常感谢!!
【问题讨论】:
标签: r