Skip to content

Instantly share code, notes, and snippets.

@hadley
Created February 11, 2013 22:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hadley/4758366 to your computer and use it in GitHub Desktop.
library(lubridate)
a <- as.Date(c("2012-01-11","2012-06-30","2012-04-18"))
b <- as.Date(c("2013-04-21","2012-03-22","2012-05-01"))
df <- data.frame(a,b)
Map2 <- function(f, x, y) {
f <- match.fun(f)
stopifnot(length(x) == length(y))
n <- length(x)
out <- vector("list", n)
for (i in seq_len(n)) {
out[[i]] <- f(x[[i]], y[[i]])
}
out
}
Map2("+", df, months(1:2))
Map2("%m+%", df, months(1:2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment