我正在尝试将一个单词拆分为双元组。我正在使用 qlcMatrix
包,但它只返回不同的二元组。例如,对于单词 "detected"
,它只返回 "te"
一次。
这是我使用的命令
test_domain <- c("detected")
library("qlcMatrix", lib.loc="~/R/win-library/3.2")
bigram1 <- splitStrings(test_domain, sep = "", bigrams = TRUE, left.boundary = "", right.boundary = "")$bigrams
这是我得到的结果:
bigram1
# [1] "ec" "ed" "de" "te" "ct" "et"
最佳答案
另一种方法是使用 base R
是使用 mapply
和 substr
:
nc <- nchar("detected")
mapply(function(x, y){substr("detected", x, y)}, x=1:(nc-1), y=2:nc)
# [1] "de" "et" "te" "ec" "ct" "te" "ed"
关于r - 如何将单词拆分为双元组,包括重复的词组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34083585/