I have a data set similar to this tibble:
~PatientID, ~A1, ~A2, ~B1, ~B2,
#--|---|---|---|---
101, "01:01", "02:01", "07:01", "51:01",
102, "02:01", "03:01", "08:01", "51:01",
103, "01:01", "03:01", "07:01", "08:01",
104, "03:01", "68:01", "14:01", "08:01"
)
They are gene types for patients. Since people have two copies of each gene, there are two columns for each gene per patient (e.g. A1 & A2). I am trying to calculate the frequency of each gene. Since the genes are spread between two columns, I am having a hard time figuring this out. Is there a way to calculate frequencies across multiple columns? My desired output would look something like this for the A gene:
| A_value | A_count |
|---|---|
| 01:01 | 2 |
| 02:01 | 2 |
| 03:01 | 3 |
| 68:01 | 1 |
Would appreciate code using dplyr, since that is what I'm trying to learn!