I have the following data frame
MyData = data.frame(
id = 1:2,
choice = factor(c('red', 'blue')),
grade = c(60, 70))
id choice grade
1 1 red 60
2 2 blue 70
I want to duplicate each row according to the level of 'choice'. Thus, row should be duplicated one time for each level of the variable 'choice'. So I need one row for the level 'blue' and one for 'red'. As follows:
id choice grade
1 1 blue 60
2 1 red 60
3 2 blue 70
4 2 red 70
I looked at several questions on stackoverflow but typically, people want to remove duplicates based on a factor, not creating them. Any idea how doing that? A solution based on tidyr/dplyr would be appreciated.