我有一个基本的角色日期来POSIXct
运作
charDateToPosixct <- function(chrDate, format, timeZone) {
as.POSIXct(chrDate, format=format, tz=timeZone)
}
我有一个日期为字符和时区的数据框。
chrDate <- c("4/25/2012","4/24/2012","4/16/2012","6/30/2012")
timeZone <- c("US/Eastern","US/Central","US/Pacific","US/Eastern")
df <- data.frame(date=chrDate,timezone=timeZone)
str(df)
'data.frame': 4 obs. of 2 variables:
$ date : Factor w/ 4 levels "4/16/2012","4/24/2012",..: 3 2 1 4
$ timezone: Factor w/ 3 levels "US/Central","US/Eastern",..: 2 1 3 2
我想将 date 的数据类型更改为POSIXct
,因此想将此函数charDateToPosixct
应用于格式为 的每一行"%m/%d/%y"
。