Advertisement
Guest User

Untitled

a guest
Aug 20th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Lines <- "1/19/1990 1.22
  2. 1/20/1990 1.25
  3. 1/23/1990 1.26
  4. 1/24/1990 1.26
  5. 1/25/1990 1.26
  6. 1/26/1990 1.26
  7. 2/1/1990 1.34
  8. 2/2/1990 1.36
  9. 2/5/1990 1.22
  10. 2/6/1990 1.22
  11. 2/7/1990 1.22
  12. 2/8/1990 1.22"
  13.  
  14. DF <- read.table(text = Lines, col.names = c("Date", "Value"))
  15. DF$Date <- as.Date(DF$Date, "%m/%d/%Y")
  16. aggregate(DF$Value, list(ym = format(DF$Date, "%Y-%m")),
  17. function(x) if (length(x) >= 5) x[5] - x[2] else NA)
  18.  
  19. library(zoo)
  20. library(chron)
  21. read.zoo(text = Lines, FUN = chron, FUN2 = as.yearmon,
  22. aggregate = function(x) if (length(x) >= 5) x[5] - x[2] else NA)
  23.  
  24. R> from <- as.Date("2009-04-07")
  25. R> to <-as.Date("2009-04-14")
  26. R> getHolidayList("UnitedStates", from, to)
  27. NULL
  28. R> to <- as.Date("2009-10-7")
  29. R> getHolidayList("UnitedStates", from, to)
  30. [1] "2009-05-25" "2009-07-03" "2009-09-07"
  31. R>
  32.  
  33. R> from <- as.Date("2009-04-07")
  34. R> to<-as.Date("2009-04-14")
  35. R> businessDaysBetween("UnitedStates", from, to)
  36. [1] 5
  37. R>
  38.  
  39. workdays = function(iniDate, endDate, holidays) {
  40. theDates = seq(from=iniDate,to=endDate,by="day")
  41. isHoliday = theDates %in% holidays
  42. isWeekend = (as.POSIXlt(theDates)$wday) %in% (c(0,6))
  43. return (sum(!isHoliday & !isWeekend))
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement