d <- tibble(
year = 2000:2009,
bedsheets = c(327, 456, 509, 497, 596, 573, 661, 741, 809, 717),
cheese = c(29.8, 30.1, 30.5, 30.6, 31.3, 31.7, 32.6, 33.1, 32.7, 32.8),
bedsheets_ind = bedsheets - lag(bedsheets),
cheese_ind = cheese - lag(cheese)
)
cor.test(~bedsheets_ind + cheese_ind, data = d)
Pearson's product-moment correlation
data: bedsheets_ind and cheese_ind
t = 0.94, df = 7, p-value = 0.4
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.424 0.817
sample estimates:
cor
0.3342