We can use gather/spread
library(tidyr)
library(dplyr)
dat %>%
gather(brand, value, -id) %>%
separate(brand, into = c('name', 'brand')) %>%
spread(name, value)
# id brand Q1r1 Q1r2
#1 A cola 0 0
#2 A pepsi 1 1
#3 B cola 0 1
#4 B pepsi 0 1
#5 C cola 1 1
#6 C pepsi 1 1