-1

I have the following dataset with 21 columns - 19 variables and Month and Date as date type columns.

The aim is to analyze how correlation change over time calculating a daily correlation between variables summarized in one month. For example, see this "monthly correlation" over time. (X-axis as month type)

+------------+---------+-----+-----+--------+---------+-------------+ | Date | Month | AOV | ASP | Clicks | Traffic | Impressions | +------------+---------+-----+-----+--------+---------+-------------+ | 2017-01-01 | 2017-01 | 50 | 6 | 700 | 10000 | 4500 | +------------+---------+-----+-----+--------+---------+-------------+ | 2017-01-02 | 2017-01 | 55 | 7 | 800 | 20000 | 4600 | +------------+---------+-----+-----+--------+---------+-------------+ | 2017-02 | 2017-02 | 58 | 8 | 700 | 4599 | 2300 | +------------+---------+-----+-----+--------+---------+-------------+

At the moment I have the following code but I only can compare two variables at the same time

ddply(corr,"Month",summarise,corr=cor(AOV,ASP))

I get the table below

+---------+------------+ | Month | corr | +---------+------------+ | 2017-1 | 0.4958738 | +---------+------------+ | 2017-10 | 0.8527522 | +---------+------------+ | 2017-11 | -0.2751771 | +---------+------------+ | 2017-12 | NA | +---------+------------+ | 2017-2 | 0.6596346 | +---------+------------+ | 2017-3 | 0.6399969 | +---------+------------+ | 2017-4 | 0.7926245 | +---------+------------+ | 2017-5 | 0.6429613 | +---------+------------+ | 2017-6 | 0.3824414 | +---------+------------+ | 2017-7 | 0.9154873 | +---------+------------+ | 2017-8 | 0.7235767 | +---------+------------+ | 2017-9 | 0.8264006 | +---------+------------+

I have been using combn to create the combinations set but I'm not quite sure how to use it with ddply. I get 171 combinations in pairs.

combn(corr,2,simplify = F)
Angelo Canepa
  • 1,701
  • 2
  • 13
  • 21
  • 1
    Do not copy paste your data here like this. Provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – M-- Dec 21 '17 at 16:35

1 Answers1

0

You can just do: cor(your_data_frame)

AidanGawronski
  • 2,055
  • 1
  • 14
  • 24