Skip to content

Instantly share code, notes, and snippets.

@Martin-Jung
Created November 6, 2018 16:25
Show Gist options
  • Save Martin-Jung/38529d4f314fb6588046a5ff354018fd to your computer and use it in GitHub Desktop.
Save Martin-Jung/38529d4f314fb6588046a5ff354018fd to your computer and use it in GitHub Desktop.
#define function to calculate area between the curves
area.between.curves <- function(yAxis1, yAxis2, xAxis)
{
d <- c(yAxis2 - yAxis1)[-1]
d <- d * diff(xAxis)
neg <- sum(abs(d[which(d < 0)]))
pos <- sum(d[which(d > 0)])
abc <- list()
if(neg > pos) abc[[1]] <- neg*-1
if(pos > neg) abc[[1]] <- pos
abc[[2]] <- c(pos, neg)/(pos+abs(neg))
return(abc)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment