Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lines <- "1/19/1990 1.22
- 1/20/1990 1.25
- 1/23/1990 1.26
- 1/24/1990 1.26
- 1/25/1990 1.26
- 1/26/1990 1.26
- 2/1/1990 1.34
- 2/2/1990 1.36
- 2/5/1990 1.22
- 2/6/1990 1.22
- 2/7/1990 1.22
- 2/8/1990 1.22"
- DF <- read.table(text = Lines, col.names = c("Date", "Value"))
- DF$Date <- as.Date(DF$Date, "%m/%d/%Y")
- aggregate(DF$Value, list(ym = format(DF$Date, "%Y-%m")),
- function(x) if (length(x) >= 5) x[5] - x[2] else NA)
- library(zoo)
- library(chron)
- read.zoo(text = Lines, FUN = chron, FUN2 = as.yearmon,
- aggregate = function(x) if (length(x) >= 5) x[5] - x[2] else NA)
- R> from <- as.Date("2009-04-07")
- R> to <-as.Date("2009-04-14")
- R> getHolidayList("UnitedStates", from, to)
- NULL
- R> to <- as.Date("2009-10-7")
- R> getHolidayList("UnitedStates", from, to)
- [1] "2009-05-25" "2009-07-03" "2009-09-07"
- R>
- R> from <- as.Date("2009-04-07")
- R> to<-as.Date("2009-04-14")
- R> businessDaysBetween("UnitedStates", from, to)
- [1] 5
- R>
- workdays = function(iniDate, endDate, holidays) {
- theDates = seq(from=iniDate,to=endDate,by="day")
- isHoliday = theDates %in% holidays
- isWeekend = (as.POSIXlt(theDates)$wday) %in% (c(0,6))
- return (sum(!isHoliday & !isWeekend))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement