Files

26 lines
615 B
R
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# rolling
# x = vector of values
# n = window size
# callback = function target, in the format "function(x){sd(x)}" or "function(x){mean(x)}"
'# 04 / 11 /2025
ℹ In group 1: `uniqueID = "PYR11_BASE_01"`.
Caused by error in `x[i:(i + n - 1)]`:
! only 0s may be mixed with negative subscripts
Added: '
lag_apply <- function(x, n, callback){
k = length(x);
result = rep(NA, k);
for(i in 1 : (k - n + 1)){ # 1 : (k - n + 1)
result[i+(n-1)] <- callback(x[i:(i + n-1)]);
}
return(result);
}
# lag_apply(subset(mean_stand_export_list, PLOT == "PYR00")$nTrees.ha, 20, function(x){mean(x)})