calculateScore <- function(x, y, measurement ){
betweenLowIndice=0
betweenHighIndice=0
result <- vector("numeric", length(measurement))
for(i in 1:length(measurement)){
for(j in 1:length(x)){
if ((measurement[i]>=x[j])&&(measurement[i]<=x[j+1])){
betweenLowIndice=j
betweenHighIndice=j+1
break
}
}
slopeAndIntercept=summary(lm(y[betweenLowIndice:betweenHighIndice]~x[betweenLowIndice:betweenHighIndice]))
score=coef(slopeAndIntercept)[2]*measurement[i]+coef(slopeAndIntercept)[1]
result[i] <- score
}
return(result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.