Skip to content

Instantly share code, notes, and snippets.

@xuanlongma
Created March 13, 2013 08:10
Show Gist options
  • Save xuanlongma/5150154 to your computer and use it in GitHub Desktop.
Save xuanlongma/5150154 to your computer and use it in GitHub Desktop.
return the maximum CCF value along with corresponding lag value
## Original arthur: vikrant @ R help mailing list
## return the maximum CCF value along with corresponding lag value
## http://r.789695.n4.nabble.com/ccf-function-td2288257.html
fun.ccfmax <- function(a,b) {
d <- ccf(a, b, plot = FALSE)
cor = d$acf[,,1]
lag = d$lag[,,1]
res = data.frame(cor,lag)
res_max = res[which.max(res$cor),]
return(res_max)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment