Question

I have a sequence from 1 to 2 which actually represents 1 to 2 minutes. I would like the increments to be in seconds. I don't think the 'chron' package will answer my problem here, because I want to make an array of numerical, decimal values not colon separated values (i.e.,1:01, 1:02).

     seq(from=1, to=2, by=0.006)

this is what I've been doing so far, at least it gives me a ratio. But I would actually just like seconds so 1.00 to 1.60 then 2 to 2.60 essentially.

is there another function that could help me out w/ this so I don't have to write an ifelse statement?

Was it helpful?

Solution

You could use ?seq.POSIXt.

s <- seq(from=as.POSIXct("1", format="%M"), to=as.POSIXct("2", format="%M"), by="sec")
s
# [1] "2012-09-11 00:01:00 CEST" "2012-09-11 00:01:01 CEST" "2012-09-11 00:01:02 CEST" ...

To convert them into your target format look for ?strftime:

as.double(strftime(s, format="%M.%S"))
# [1] 1.00 1.01 1.02 ... 1.58 1.59 2.00
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top