calculating correlations by group using ddply [R Studio]

Hey everyone!

I am new here and new to R Studio.
I have a question and am hoping that maybe someone can help me out.
This is a snapshot of the dataset that I am working with

head(Clearing_Dates_CDS_Spreads)
date average_correlation Reference_Entity
1 2009-02-12 0.4631034 EDP - Energias de Portugal, S.A.
2 2009-02-12 0.4631034 International Business Machines Corporation
3 2009-02-12 0.4631034 Domtar Corporation
4 2009-02-12 0.4631034 MetLife, Inc.
5 2009-02-12 0.4631034 Caterpillar Inc.
6 2009-02-12 0.4631034 GKN HOLDINGS PLC
Days_Left_Until_Clearing
1 -333
2 -431
3 -2349
4 -788
5 -368
6 -1845

So, I've got four rows: date - average correlation - reference entity - days left until clearing.
In total I have 1.076.435 entries: the date is ranging from 12.02.2009 to 04.06.2018 and it is repeated in its column a total of 461 times because we have 461 reference entities who each have a certain amount of days left until they have to be cleared. The average correlation that is already in the dataset is the average of the daily correlations of fourteen banks which were a part of my sample for this analysis.

Now, what I have to do is calculate the average correlation for all of the correlations that are listed as having for example 300 days left until clearing. And then the average correlation for all of the correlations that have 299 days left until clearing and so on and so forth. I have been told that the package "ddply" is the one to work with for this, but as I am a newbie to all of this, I haven't been able to get it to work.

Can someone perhaps be of help to me?
Thanks to everyone in advance!

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Or at least some sample data on a copy/paste friendly format? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.