0

I am trying to find the area under a solar radiation intensity graph at a series of continuous time points. Basically I want the integral of the past 24hours of solar radiation every hour over a 7 day period - a moving sum of the past 24 hours - (I suspect that temperature in the soil is a result of the past 24 hours of solar radiation)

Here is the code i am using, it works but I would like to automate it so I can change the time window of integration easily (try 12, 18, 24,36 hours ) and obtain a printed/saved table of hourly integrated solar radiation values that I may plot against my hourly temperature data to see if there is a relationship)

Here: Rg -solar radiation in 10min measurements num - entry number in dataframe AUC_xxx - Total solar radiation over the past 24 hours

y<-as.numeric(xx$Rg[xx$num["2015-09-13 14:10"]:xx$num["2015-09-14 14:00"]])
x<-c(1:length(y))
id <- order(x)
AUC_s14_14 <- sum(diff(x[id])*rollmean(y[id],2))

I tried with rollapply, but I'm stuck again:

 rollapply(xx$Rg[xx$num["2015-09-13 00:10"]:xx$num["2015-09-14 00:00"]],    width = 144, by = 6, FUN = **"INTEGRAL"**, na.rm = TRUE, align = "left")

Thanks for the help !

Kyle B.
  • 13
  • 4
  • Post some real or fake data (or a link to some data). Should be possible with `approxfun` and `integrate`. – IRTFM Jul 06 '16 at 23:26
  • Thanks for the suggestion ! I just realised that if I use "sum" in rollapply I will get the same as the integral, as the spaces between all points is equal to 1- so essentially calculating a running mean of 144 values (144 10min values = 24 hours) over a time step of 1, will give the integrated 24hour value for every data point ! – Kyle B. Jul 07 '16 at 10:47

0 Answers0