I have loaded data in the following format:
| Gender | Yes | No |
|---|---|---|
| Male | 2 | 1 |
| Female | 1 | 2 |
I would like to expand it to:
| Gender | Result |
|---|---|
| Male | Yes |
| Male | Yes |
| Male | No |
| Female | Yes |
| Female | No |
| Female | No |
I've tried using the expand.table function in epitools but have not succeeded.
Using
tidyr, you can pivot the data into long format, thenuncountit.Assuming your data is called
df, you could do that as follows:Data used, taken from question and put into reproducible format