I've got a dataset comparing `yes`/`no` data for options `A`/`B`/`C`/`D`. I want to work out the proportions of each option `A`/`B`/`C`/`D` that are `yes`, and work out the absolute and relative difference in proportion compared to the proportion of `A` that are `yes`.

If there's a more efficient way to get to this relative and absolute change in proportions compared to a reference proportion, I would be really interested to hear about that too! So far, I've been using `dplyr`, I'm happy to use another library if it achieves the desired result.

**Data:**

My data is in the following format:

```
> str ( df )
'data.frame':   589 obs. of  2 variables:
 $ grp1: Factor w/ 4 levels "A","B","C","D": 3 1 2 1 3 3 4 2 2 1 ...
 $ grp2: Factor w/ 2 levels "N","Y": 1 2 1 1 1 1 1 2 2 2 ...
>
> table ( df )
    grp2
grp1   N   Y
   A  81  40
   B 144  61
   C 117  38
   D  88  20

```

**Proportions:**

I've calculated the proportions of `yes`/(`yes` + `no`) as follows:

```
>library ( dplyr )
> df %>%
+      group_by ( grp1 , grp2 ) %>%
+      summarise ( n = n () ) %>% 
+      mutate ( total = sum ( n ) ) %>%
+      mutate ( prop = n / sum ( n ) ) %>% 
+      filter ( grp2 == "Y" )
# A tibble: 4 x 4
# Groups:   grp1 [4]
  grp1  grp2      n total prop
  <fct> <fct> <int> <int> <dbl>
1 A     Y        40   121 0.331
2 B     Y        61   205 0.298
3 C     Y        38   155 0.245
4 D     Y        20   108 0.185

```

**What I want:**

Hard coded, `difference.absolute` = `prop` - 0.331, `difference.relative` = `prop` / 0.331.
I want the code to use the first value of the `prop` column as the reference value, rather than have me specify the reference value manually.

```
  grp1  grp2      n  total   prop  difference.absolute  difference.relative
1 A     Y        40    121  0.331                    0                    1
2 B     Y        61    205  0.298              -0.0334                0.899
3 C     Y        38    155  0.245              -0.0858                0.741
4 D     Y        20    108  0.185               -0.146                0.559

```