gpt4 book ai didi

R - 如果顺序不同,如何比较两个单词的句子?

转载 作者:行者123 更新时间:2023-12-02 00:52:09 25 4
gpt4 key购买 nike

举个例子

z <- "Dikesh Faldu"
y <- "Faldu Dikesh"

我想处理这两个变量并给我与“DikeshFaldu”相同的输出

再举个例子

我有一个具有所有这些值的变量

[1] dikesh faldu
[2] xyz abc
[3] faldu dikesh
[4] anything like
[5] but only
[6] two words
[7] only but

…………

然后我想要这样的输出

[1] dikeshfaldu
[2] xyzabc
[3] dikeshfaldu
[4] anythinglike
[5] butonly
[6] twowords
[7] butonly

[1] faldudikesh
[2] xyzabc
[3] faldudikesh
[4] anythinglike
[5] onlybut
[6] twowords
[7] onlybut

最佳答案

根据@zx8754、@Dirty Sock Sniffer 和@RHertel 的输入,您可以尝试,

sapply(strsplit(charvec, " "), function(x) paste(sort(x), collapse=""))

#[1] "dikeshfaldu" "abcxyz" "dikeshfaldu" "anythinglike" "butonly"
#[6] "twowords" "butonly"

在哪里

charvec <- c("dikesh faldu", "xyz abc", "faldu dikesh", "anything like", 
"but only", "two words", "only but")

关于R - 如果顺序不同,如何比较两个单词的句子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911458/

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