如果the_date
列如下,如何将日期和时间分成2个不同的变量:
the_date
12/25/17 0:00
如何分别检索
答案 0 :(得分:1)
转换为DateTime之后,我们提取每个组件
library(lubridate)
library(dplyr)
df1 %>%
mutate(v1 = mdy_hm(v1),
Year = year(v1),
Month = month(v1),
Date = day(v1),
time = format(v1, "%H:%M:%S"))
# A tibble: 1 x 5
# v1 Year Month Date time
# <dttm> <dbl> <dbl> <int> <chr>
#1 2017-12-25 00:00:00 2017 12 25 00:00:00
df1 <- tibble(v1 = "12/25/17 0:00")