# How to test if I can use cross-correlation?

I want to compare two time series in R and see if they are cross-correlated (with ccf).

I believe that they have to be stationary? How that my data is stationary in R and are there any other requirements before I can do ccf?

The sample cross correlation function is useful to identify which variable is leading or lagging. You can learn more about it here. Note that if you have non-stationary data you may find some spurious correlation between the two series, so you must first check if this is the case.

To check if a series is stationary you can use unit root tests. The most common is the Augmented Dickey Fuller test. It can be implemented in R with the urca package using the following code:

library(urca)
adf <- ur.df(x, type = "drift", lags = 10, selectlags = "AIC")