怎么留下第一次打卡时间和最后一次打卡时间呢
如果只有一个打卡时间 就留下它本身就行
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
library(xfun)
# read_utf8('range_time.csv')
library(data.table)
data <- fread('range_time.csv')
library(tidyverse)
data %>%
select(V1) %>%
mutate(V1_e = str_extract_all(V1,'[0-9]{2}:[0-9]{2}:[0-9]{2}')) %>%
mutate(V1_max = map_chr(V1_e,max,na.rm=T)) %>%
mutate(V1_min = map_chr(V1_e,min,na.rm=T))
library(tidyverse)
data %>%
mutate_all(~str_extract_all(.,'[0-9]{2}:[0-9]{2}:[0-9]{2}')) %>%
mutate_all(
function(x){
# x_max = map_chr(x,max,na.rm=T)
# x_min = map_chr(x,min,na.rm=T)
# text = paste0(x_max,x_min,collapse = ',')
# return(text)
map_chr(x
# ,length
,~case_when(
length(.) == 0 ~ '-'
,length(.) == 1 ~ max(.)
,length(.) >= 2 ~ paste(max(.,na.rm = T)
,min(.,na.rm = T)
,sep = ',')
)
)
}
) %>%
head
## V1 V2 V3 V4 V5
## 1 - - - <NA> <NA>
## 2 08:56:00,00:11:00 20:00:00,10:09:00 13:41:00,09:00:00 <NA> <NA>
## 3 18:44:00,09:31:00 19:00:00,09:34:00 20:04:00,09:33:00 <NA> <NA>
## 4 17:11:00,09:09:00 17:19:00,09:23:00 17:09:00,08:58:00 <NA> <NA>
## 5 19:15:00,09:46:00 18:49:00,10:05:00 19:24:00,10:01:00 <NA> <NA>
## 6 18:47:00,09:46:00 22:05:00,09:31:00 20:03:00,09:33:00 <NA> <NA>
## V6 V7 V8 V9
## 1 - - - -
## 2 18:48:00,09:01:00 19:23:00,09:00:00 20:20:00,09:09:00 19:01:00,09:07:00
## 3 18:57:00,09:19:00 18:47:00,09:42:00 20:20:00,09:30:00 18:54:00,09:40:00
## 4 17:16:00,09:09:00 17:26:00,09:05:00 17:43:00,09:14:00 17:50:00,09:13:00
## 5 19:11:00,09:58:00 19:06:00,09:56:00 19:17:00,10:01:00 19:18:00,10:04:00
## 6 18:57:00,09:37:00 18:42:00,09:30:00 20:18:00,09:42:00 18:39:00,09:16:00
## V10 V11 V12 V13 V14
## 1 - <NA> <NA> - -
## 2 13:31:00,09:09:00 <NA> <NA> 18:16:00,09:01:00 18:16:00,08:49:00
## 3 13:31:00,09:31:00 <NA> <NA> 19:01:00,09:46:00 18:36:00,09:35:00
## 4 13:27:00,09:15:00 <NA> <NA> 18:08:00,09:06:00 17:11:00,08:55:00
## 5 18:00:00,09:59:00 <NA> <NA> 18:56:00,09:40:00 19:15:00,09:54:00
## 6 13:31:00,09:51:00 <NA> <NA> 20:01:00,09:50:00 18:36:00,09:34:00
## V15 V16 V17 V18 V19
## 1 - - - <NA> <NA>
## 2 18:09:00,09:03:00 18:15:00,09:07:00 18:16:00,09:13:00 <NA> <NA>
## 3 18:00:00,09:35:00 18:46:00,09:34:00 18:40:00,09:37:00 <NA> <NA>
## 4 17:12:00,09:09:00 17:29:00,09:13:00 17:24:00,09:19:00 <NA> <NA>
## 5 19:22:00,09:54:00 19:00:00,09:53:00 - <NA> <NA>
## 6 18:39:00,09:31:00 18:51:00,09:46:00 18:43:00,09:41:00 <NA> <NA>
## V20 V21 V22 V23
## 1 - - - -
## 2 18:12:00,09:10:00 18:35:00,09:24:00 18:30:00,09:29:00 18:17:00,08:54:00
## 3 19:17:00,09:25:00 18:32:00,09:27:00 18:43:00,09:35:00 18:54:00,09:29:00
## 4 17:22:00,09:16:00 17:44:00,09:30:00 17:36:00,09:35:00 -
## 5 19:18:00,09:59:00 19:13:00,10:03:00 19:08:00,10:05:00 19:20:00,09:57:00
## 6 18:54:00,09:35:00 18:35:00,09:33:00 18:46:00,09:43:00 18:54:00,09:42:00
## V24 V25 V26 V27 V28
## 1 - <NA> <NA> - -
## 2 18:08:00,08:58:00 <NA> <NA> 18:05:00,08:51:00 18:11:00,08:52:00
## 3 20:01:00,09:31:00 <NA> <NA> 09:28:00 18:39:00,09:38:00
## 4 - <NA> <NA> 17:06:00,08:58:00 17:19:00,08:58:00
## 5 19:26:00,10:14:00 <NA> <NA> 19:20:00,09:57:00 19:10:00,10:00:00
## 6 18:37:00,09:28:00 <NA> <NA> 18:36:00,09:31:00 18:39:00,09:37:00
## V29 V30 V31
## 1 - - -
## 2 18:12:00,09:08:00 18:11:00,09:07:00 18:13:00,08:55:00
## 3 18:38:00,09:30:00 18:43:00,09:36:00 18:35:00,09:35:00
## 4 17:19:00,09:14:00 17:15:00,09:12:00 18:00:00,09:02:00
## 5 19:10:00,09:56:00 19:16:00,09:51:00 18:45:00,09:46:00
## 6 18:46:00,09:37:00 18:46:00,09:39:00 18:33:00,09:30:00
NA
和character(0)
的情况