https://github.com/cran/spacetime
Tip revision: 58c241102e4635105db33ed1fe8628f3fa808f46 authored by Edzer Pebesma on 12 September 2011, 00:00:00 UTC
version 0.5-5
version 0.5-5
Tip revision: 58c2411
apply.R
# or is this too trivial to provide?
STapply = function(X, MARGIN, FUN, ...) {
stopifnot(class(X) == "STFDF")
if (MARGIN == "space" || MARGIN == 1)
FOREACHSPACEapply(X, FUN, ...)
else if (MARGIN == "time" || MARGIN == 2)
FOREACHTIMEapply(X, FUN, ...)
else stop("MARGIN should be 1 (space) or 2 (time)")
}
FOREACHSPACEapply = function(X, FUN, ...) {
ret = lapply(1:length(X@sp), function(i) FUN(X[i,], ...))
#STFDF(X@sp, ret[[1]], do.call(rbind, ret))
}
FOREACHTIMEapply = function(X, FUN, ...) {
ret = lapply(1:nrow(X@time), function(i) FUN(X[,i], ...))
}