以秒为单位从数字转换为时间

编程入门 行业动态 更新时间:2024-10-26 04:25:34
本文介绍了以秒为单位从数字转换为时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 12:19:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   单位   数字   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!