我有一列军事时间值,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
如果有人能指出我的错误或提出更好的方法来完成这项任务,我将不胜感激。