Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 18th, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do you generate a sequence of the last day of the month over two years in R?
  2. ymd("2010-01-31")+months(0:23)
  3.        
  4. [1] "2010-01-31 UTC" "2010-03-03 UTC" "2010-03-31 UTC" "2010-05-01 UTC" "2010-05-31 UTC" "2010-07-01 UTC" "2010-07-31 UTC" "2010-08-31 UTC" "2010-10-01 UTC"
  5. [10] "2010-10-31 UTC" "2010-12-01 UTC" "2010-12-31 UTC" "2011-01-31 UTC" "2011-03-03 UTC" "2011-03-31 UTC" "2011-05-01 UTC" "2011-05-31 UTC" "2011-07-01 UTC"
  6. [19] "2011-07-31 UTC" "2011-08-31 UTC" "2011-10-01 UTC" "2011-10-31 UTC" "2011-12-01 UTC" "2011-12-31 UTC"
  7.        
  8. ymd("2010-01-31")+ as.period(months(0:23))
  9.        
  10. Error in as.period.default(months(0:23)) :
  11.   (list) object cannot be coerced to type 'double'
  12.        
  13. R> seq(as.Date("2010-02-01"), length=24, by="1 month") - 1
  14.  [1] "2010-01-31" "2010-02-28" "2010-03-31" "2010-04-30" "2010-05-31"
  15.  [6] "2010-06-30" "2010-07-31" "2010-08-31" "2010-09-30" "2010-10-31"
  16. [11] "2010-11-30" "2010-12-31" "2011-01-31" "2011-02-28" "2011-03-31"
  17. [16] "2011-04-30" "2011-05-31" "2011-06-30" "2011-07-31" "2011-08-31"
  18. [21] "2011-09-30" "2011-10-31" "2011-11-30" "2011-12-31"
  19. R>
  20.        
  21. ymd("2010-02-01")+ months(0:23)-days(1)
  22.        
  23. [1] "2010-01-31 UTC" "2010-02-28 UTC" "2010-03-31 UTC" "2010-04-30 UTC" "2010-05-31 UTC" "2010-06-30 UTC" "2010-07-31 UTC" "2010-08-31 UTC" "2010-09-30 UTC"
  24. [10] "2010-10-31 UTC" "2010-11-30 UTC" "2010-12-31 UTC" "2011-01-31 UTC" "2011-02-28 UTC" "2011-03-31 UTC" "2011-04-30 UTC" "2011-05-31 UTC" "2011-06-30 UTC"
  25. [19] "2011-07-31 UTC" "2011-08-31 UTC" "2011-09-30 UTC" "2011-10-31 UTC" "2011-11-30 UTC" "2011-12-31 UTC"