I have a dataset which contains count data where the structure looks like:

| Sample | ID | Expected | Observed\_A | Observed\_B |
| --- | --- | --- | --- | --- |
| A | id1 | 10 | 8 | 10 |
| A | id2 | 6 | 8 | 4 |
| B | id1 | 15 | 12 | 18 |
| B | id2 | 1 | 2 | 4 |

What I'm trying to get to with tidyr/dplyr is the per-sample correlation between each of the observed counts and the expected counts (i.e. I'm unfussed by the correlation between each of the observed columns).

| Sample | Dataset | Correlation |
| --- | --- | --- |
| A | Observed\_A | 0.99 |
| A | Observed\_B | 0.93 |
| B | Observed\_A | 0.89 |
| B | Observed\_B | 0.91 |

I can do this by looping, but was wondering whether there is a 'clearer' approach to take using tidyverse functions?

Any help much appreciated!!