I would use a combination of expandRows
from my "splitstackshape" package and melt
from "reshape2".
Assuming your data are called "mydf", try:
library(splitstackshape)
library(reshape2)
dfLong <- expandRows(
melt(mydf, measure.vars = c("Yes", "No"),
variable.name = "answer"), "value")
Here are the first 20 rows:
head(dfLong, 20)
# age color place answer
# 1 12-18 red right Yes
# 1.1 12-18 red right Yes
# 1.2 12-18 red right Yes
# 1.3 12-18 red right Yes
# 1.4 12-18 red right Yes
# 1.5 12-18 red right Yes
# 1.6 12-18 red right Yes
# 1.7 12-18 red right Yes
# 1.8 12-18 red right Yes
# 1.9 12-18 red right Yes
# 1.10 12-18 red right Yes
# 1.11 12-18 red right Yes
# 2 19-30 yellow left Yes
# 2.1 19-30 yellow left Yes
# 3 12-18 red right No
# 3.1 12-18 red right No
# 3.2 12-18 red right No
# 3.3 12-18 red right No
# 3.4 12-18 red right No
# 4 19-30 yellow left No
## Confirm that there are the correct number of combinations
table(dfLong$age, dfLong$answer)
#
# Yes No
# 12-18 12 5
# 19-30 2 33
The order is a little bit different from what you've posted--doing all "Yes" answers first and then the "No" answers instead of alternating between them.