Skip to content

Instantly share code, notes, and snippets.

@steveharoz
Last active January 16, 2016 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveharoz/2916944e3405eaaacd82 to your computer and use it in GitHub Desktop.
Save steveharoz/2916944e3405eaaacd82 to your computer and use it in GitHub Desktop.
Learning how to make a sequence along a time axes
mydate1 = as.Date("2000-01-01")
mydate2 = as.Date("2000-03-01")
# EASY: sequence with every other int
seq(1, 60, by=2)
# HARD: sequence with every other day
seq(mydate1, mydate2, by=???) # day?
# pretend you're new to R
# you don't know about lubridate or POSIX
# try to discover the answer as though you're naive
# start from ?seq and google searches
# HARDER: sequence sampled at 2x per day (every 12 hours)
seq(mydate1, mydate2, ???)
# HINT: things that don't work:
seq(mydate1, mydate2, days(2))
seq(mydate1, mydate2, hours(12))
seq(mydate1, mydate2, by=0.5)
seq(mydate1, mydate2, length.out=120)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment