0

I want to calculate the area under the curve for each column of a big data frame in which the limits for the integration are different in each column and are stored in a different data frame (df2). Particularly, df2 indicates the position of the start and end point for the integration.

n = 1:100

s = 52:151

b = 68:167

df = data.frame(n, s, b) 


start = c(45,50,38)

end = c(68,70,72)

df2 = data.frame(start, end)

I used the function auc from MESS library, in order to calculate the auc from one column, but I have stacked to do it for all

Can anyone provide some suggestions that how I can do this? There is another package which fits better in my problem?

Thank you in advance

Jaap
  • 81,064
  • 34
  • 182
  • 193

1 Answers1

0

Results in a vector:

x <- 1:100 #I guess

setNames(
  sapply(seq_len(ncol(df)), 
         function(i) auc(x, df[[i]], df2$start[i], df2$end[i]) ),
  names(df)
  )

or as data frame:

df3 <- as.data.frame( setNames(
  lapply(seq_len(ncol(df)),
         function(i) auc(x, df[[i]], df2$start[i], df2$end[i]) ),
  names(df)
  ))
bergant
  • 7,122
  • 1
  • 20
  • 24