First commit with the code Hector shared with me
This commit is contained in:
26
10_EXPORTS/lag_apply.R
Normal file
26
10_EXPORTS/lag_apply.R
Normal file
@@ -0,0 +1,26 @@
|
||||
# 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)})
|
||||
Reference in New Issue
Block a user