Here is the reproductible example (at least on my computer)
a <- as.Date(as.Date("2012-10-01"):as.Date("2013-03-25"))
myFun <- function (x) {
return(sqrt(abs(as.numeric(x-as.Date("2013-01-01")))))
}
for (i in 1:length(a)) {
print(myFun(a[i]))
}
works fine but
sapply(a,myFun)
fails with error message
"Error in `-.Date`(x, as.Date("2013-01-01")) :
Can only subtract from Date objects"
All ideas are welcome !
Cheers