答案 0 :(得分:1)
base
解决方案:
f = "%m/%d/%y" # note the lowercase y; it's because the year is 92, not 1992
dataset$SetDateMonth <- format(as.POSIXct(dataset$SetDate, format = f), "%m")
基本上,它的作用是将列从character
(假定的类)转换为POSIXct
,从而可以轻松提取月份信息。
快速测试:
format(as.POSIXct('1/1/92', format = "%m/%d/%y"), "%m")
[1] "01"
答案 1 :(得分:0)
尝试一下(创建了一个小示例):
4 can connect
5 create new database successfully
6 after creating a new database on creating new tables Sequel Pro stop working...
如果希望将整月用作字符串,请使用:
library(lubridate)
date_example <- "1/1/92"
lubridate::mdy(date_example)
[1] "1992-01-01"
lubridate::mdy(date_example) %>% lubridate::month()
[1] 1