状态更新信息
"Placed | 2018-06-23 08:46:46 Acknowledged | 2018-06-23 08:53:03 Dispatched | 2018-06-23 09:02:54 Completed | 2018-06-23 09:03:12"
"Placed | 2018-06-23 09:03:28 Acknowledged | 2018-06-23 09:03:43 Dispatched | 2018-06-23 09:06:31 Completed | 2018-06-23 09:06:46"
我想要以上数据无关列: 一栏应该有 放置/确认/发送/完成以及其他应具有日期和时间。
我们如何在Excel和R中做到这一点?
答案 0 :(得分:0)
在R
library(tidyr)
library(dplyr)
df %>% mutate(A = gsub("Placed\\s+\\||Acknowledged|Dispatched|Completed","",A)) %>%
separate(A,c('Placed',"Acknowledged","Dispatched","Completed"),'\\|') %>%
mutate_all(funs(trimws(., which = 'both')))
Placed Acknowledged Dispatched Completed
1 2018-06-23 08:46:46 2018-06-23 08:53:03 2018-06-23 09:02:54 2018-06-23 09:03:12
2 2018-06-23 09:03:28 2018-06-23 09:03:43 2018-06-23 09:06:31 2018-06-23 09:06:46
数据
df <- read.table(text="
A
'Placed | 2018-06-23 08:46:46 Acknowledged | 2018-06-23 08:53:03 Dispatched | 2018-06-23 09:02:54 Completed | 2018-06-23 09:03:12'
'Placed | 2018-06-23 09:03:28 Acknowledged | 2018-06-23 09:03:43 Dispatched | 2018-06-23 09:06:31 Completed | 2018-06-23 09:06:46'
",header=T, stringsAsFactors = F)