I am searching for a solution how to transform the following data frame using dplyr:
item <- c('A','B','C')
one <- c(2, 1, 2)
two <- c(1,1,2)
data <- data.frame(item,one,two)
data
item | one | two |
---|---|---|
A | 2 | 1 |
B | 1 | 1 |
C | 2 | 2 |
Now, the column "one" contains the number of ratings of the value 1, the column "two" the number of ratings of the value 2. My ideal data frame after transformation would look like this:
item | rating |
---|---|
A | 1 |
A | 1 |
A | 2 |
B | 1 |
B | 2 |
C | 1 |
C | 1 |
C | 2 |
C | 2 |
Any idea how I could get to this output (it doesn't have to be dplyr)? I know how to use pivot_longer of the tidyr package but that doesn't solve the problem of repeating the number of rows...