[go: up one dir, main page]

File: apply.R

package info (click to toggle)
r-cran-spacetime 1.3-3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,240 kB
  • sloc: sh: 13; makefile: 2
file content (18 lines) | stat: -rw-r--r-- 570 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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], ...))
}