【发布时间】:2019-11-02 10:27:30
【问题描述】:
我的数据集看起来像这样 -
dataset = data.frame(Comments=c('Wow... Loved this place. 1','Crust is not good. 0','Not tasty and the texture was just nasty. 0'))
我正在尝试将数据集拆分为两列,使第一列仅包含文本,第二列仅包含每个字符串末尾的数字。
这是我的尝试
library(dplyr)
library(tidyr)
dataset = dataset %>%
separate(Comments, into = c("Comment", "Score"), sep = " (?=[^ ]+$)")
但是我没有得到完美的分离。我在网上查看了其他解决方案,但还没有运气。
对此的任何帮助将不胜感激。
【问题讨论】:
-
你能在一个句点后面加上 >1 个空格吗?从您的示例数据集中,这将在这里工作