我想计算每个网格方块过去三天的降雨量,并将其添加为我的data.table中的新列.为了清楚起见,我想总结一下当前和上一天的降雨量,对于每个气象网格广场
library ( zoo )
library (data.table)
# making the data.table
rain <- c(NA, NA, NA, 0, 0, 5, 1, 0, 3, 10) # rainfall values to work with
square <- c(1,1,1,1,1,1,1,1,1,2) # the geographic grid square for the rainfall measurement
desired_result <- c(NA, NA, NA, NA, NA, 5, 6, 6, 4, NA ) # this is the result I'm looking for (the last NA as we are now on to the first day of the second grid square)
weather …Run Code Online (Sandbox Code Playgroud)