我有一个很长的时间序列(动物园)的降水数据,我知道如何获得月平均值:
library(hydroTSM)
ma= monthlyfunction(data, mean, na.rm=TRUE)
我也知道如何获得每月的价值总和:
su= monthlyfunction(data, sum, na.rm=TRUE)
但是对于最后一个,我得到了整个时间段的每月总和。我想得到月平均值,我的意思是例如:
jan 1980 (sum)= 150
jan 1981 (sum)= 180
jan 1982 (sum)= 90
expected value for january = average(150,180,90)= 140
是否有一个功能,而不是平均值和总和?
library(hydroTSM)
#This data is daily streamflows, but is similar to Precipitation
data(OcaEnOnaQts)
x <- OcaEnOnaQts
#In case you want monthly precipitation in "precipitation / 30 days" (what is common) you can use
monthlyfunction(x, FUN=mean, na.rm=TRUE) * 30
#In case you want the precipitation per days in specific month you can use
monthlyfunction(x, FUN=mean, na.rm=TRUE) * as.vector(dwi(x, out.unit = "months") * mean(dwi(x)) / sum(dwi(x)))
#or approximately
monthlyfunction(x, FUN=mean, na.rm=TRUE)*c(31,28.25,31,30,31,30,31,31,30,31,30,31)
#Add: Some ways to come to the mean monthly precipitation
p1980 <- c(rep(0,28), 50, 50, 50) #sum = 150
p1981 <- c(rep(0,28), 60, 60, 60) #sum = 180
p1982 <- c(rep(0,28), 30, 30, 30) #sum = 90
#
mean(c(sum(p1980), sum(p1981), sum(p1982))) # = 140 This is how you want it to be calculated
mean(c(p1980, p1981, p1982))*31 # = 140 This is how I suggested to come to the result
#Some other ways to come to the mean monthly precipitation
mean(c(mean(p1980), mean(p1981), mean(p1982)))*31 # = 140
sum(c(p1980, p1981, p1982))/3 # = 140