【发布时间】:2021-02-01 01:42:25
【问题描述】:
我有一列军事时间值,df1$appt_times,格式为“13:30”,全部为 5 个字符,“00:00”。我已经尝试过 POSIXct,但它在值中添加了今天的日期。我也尝试过 lubridate,但无法让它发挥作用。最近我正在尝试使用 chron 并且到目前为止也没有成功
目标是,一旦完成,我会将时间分组为因子级别,目前我无法对它们执行任何条件操作,除非我也错了;)
> df1$Time <- chron(times = df1$appt_time)
Error in convert.times(times., fmt) : format h:m:s may be incorrect
In addition: Warning message:
In unpaste(times, sep = fmt$sep, fnames = fmt$periods, nfields = 3) :
106057 entries set to NA due to wrong number of fields
还有df1$Time <- chron(times(df1$appt_time))和上面一样的错误
以及使用格式明确的不同尝试:
> df1$appt_time <- chron(df1$appt_time, format = "h:m")
Error in widths[, fmt$periods, drop = FALSE] : subscript out of bounds
如果有人能指出我的错误或提出更好的方法来完成这项任务,我将不胜感激。
【问题讨论】:
-
检查日期格式在 R 中的工作方式:stat.berkeley.edu/~s133/dates.html
-
@Turksarama - 不幸的是,您的链接没有任何用处。如果您有任何关于如何将条件逻辑应用于时间值的信息,请告诉我