Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要能够在 R 中反转单词。例如将“这是我的文本”转换为“我的文本是这个”。我尝试使用 stringr 包中的 word 函数,如下所示,但没有用,只得到“”
word("this is my text", -1,1) [1] ""
任何建议为什么上述不起作用或任何其他方式来反转单词?
我们可以做一个strsplit然后用rev
strsplit
rev
paste(sapply(strsplit(str1, "\\s+"), rev), collapse= ' ') #[1] "text my is this"
str1 <- "this is my text"