gpt4 book ai didi

r - 如何将单词拆分为双元组,包括重复的词组?

转载 作者:行者123 更新时间:2023-12-04 11:54:01 27 4
gpt4 key购买 nike

我正在尝试将一个单词拆分为双元组。我正在使用 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是使用 mapplysubstr :

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com