R 中具有小数秒间隔的序列 [英] Sequence with fractional second intervals in R

查看:47
本文介绍了R 中具有小数秒间隔的序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 R 中创建一个间隔以小数秒为单位的连续序列?

How would I create a continuous sequence with an interval in fractional seconds in R?

例如,我需要 0.03125 秒的跳跃.

For example, I need jumps of 0.03125 seconds.

我这样做是否正确?:

seq(from=as.POSIXct("14:03:55","%H-%M-%S",tz="UTC"),
to=as.POSIXct("19:30:07", "%H-%M-%S", tz="UTC"),
by="seconds",
length=0.0315)

谢谢!

推荐答案

as.POSIXct 的格式参数需要有冒号而不是连字符以匹配时间值的格式.by 应该是序列中值之间的间隔.length.out 可用于指定序列中所需值的总数,而不是用 by 指定间隔.

The format argument to as.POSIXct needs to have colons instead of hyphens to match the format of the time values. by should be the interval between values in the sequence. length.out can be used to specify the total number of values you want in the sequence, rather than specifying the interval with by.

options(digits.secs=4) 

time.seq = seq(from=as.POSIXct("14:03:55", format="%H:%M:%OS",tz="UTC"),    
    to=as.POSIXct("19:30:07", format="%H:%M:%OS", tz="UTC"), by=0.0315)

head(time.seq)
[1] "2016-01-21 14:03:55.0000 UTC" "2016-01-21 14:03:55.0315 UTC"
[3] "2016-01-21 14:03:55.0629 UTC" "2016-01-21 14:03:55.0945 UTC"
[5] "2016-01-21 14:03:55.1259 UTC" "2016-01-21 14:03:55.1575 UTC"

请注意,由于没有给出日期,as.POSIXct 会将今天的日期附加到时间值上.

Note that since there's no date given, as.POSIXct attaches today's date to the time values.

这篇关于R 中具有小数秒间隔的序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆