gpt4 book ai didi

r - 将R中的单词与数字分开

转载 作者:行者123 更新时间:2023-12-02 04:36:36 26 4
gpt4 key购买 nike

如何在单词和数字之间创建空格?我一直在搜索 SO,但没有找到 R 的结果。

我有这样的数据框:

1 This is the case34
2 To to that case23/234
3 Only Monday223.23

期望的输出:

1 "This is the","case 34"
2 "To to that","case 23/234"
3 "Only","Monday 223.23"

如此将数字与单词分开,如何处理?

最佳答案

尝试像这样使用 read.tablesub:

# data in reproducible form
DF <- data.frame(s=c("This is the case34", "To to that case23/234", "Only Monday223.23"))

read.table(text = sub("(.*\\S) ([[:alpha:]]+)(\\d.+)$", "\\1,\\2 \\3", DF$s), sep = ",")

它给出了这个数据框:

           V1            V2
1 This is the case 34
2 To to that case 23/234
3 Only Monday 223.23

下次请以可复制的形式提供您的数据。

关于r - 将R中的单词与数字分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21850191/

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