Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
721 views
in Technique[技术] by (71.8m points)

r - Generating sequence of dates

i would like to generate sequence of dates with next code:

vm1=strptime("2000-01-01 00:00:00", format="%Y-%m-%d %H:%M:%S")
vm2=strptime("2011-12-31 23:55:00", format="%Y-%m-%d %H:%M:%S")
vm3=seq(vm1, vm2, by = min(300))

The problem is that on some specific date program changes time zone and omits part of generated data. For example:

vm3[24500:24510]

I would appreciate any help or instructions.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That section of vm3 looks fine to me (UK locale, GMT/BST time zone). Consider forcing your dates to be in universal time, and then correcting to your local time zone later on.

vm1=strptime("2000-01-01 00:00:00", format="%Y-%m-%d %H:%M:%S", tz = "UTC")
vm2=strptime("2011-12-31 23:55:00", format="%Y-%m-%d %H:%M:%S", tz = "UTC")
vm3=seq(vm1, vm2, by = "300 mins")
any(is.na(vm3)) #FALSE

BTW, you want a by argument of "300 mins", not min(300). min is the minimum function; it has nothing to do with minutes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...