问题描述
限时送ChatGPT账号..我有一份完成调查所需的持续时间列表.目前采用数字形式.
I have a list of durations that it took to complete a survey. Currently in numeric form.
duration
275
207
197
251
651
278
20
343
class(survey$duration)
给出数字"
我希望 R 将这些读取为秒.我不需要任何日期或任何东西,与原始输出相同,但 R 将其识别为时间,而不是数字.
I want R to read these as seconds. I don't need any dates or anything, same output as it was original but for R to recognize it as time, not numeric.
我试过了survey$duration<-as.POSIXct(strptime(survey$duration, tz = "GMT", format = "%S"))
但结果也给出了日期.
I have tried
survey$duration<-as.POSIXct(strptime(survey$duration, tz = "GMT", format = "%S"))
but the result gives dates as well.
非常感谢!
推荐答案
lubridate 库可以将时间存储为 Duration、Intervals 或 Periods.这可能就是您要找的:
The lubridate library can store times as Durations, Intervals, or Periods. This might be what you are looking for:
duration_Vec<-sample(1:1000,10)
library(lubridate)
as.duration(duration_Vec)
这篇关于以秒为单位从数字转换为时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论