beer <- c("1"="BUD LIGHT","2"="BUSCH LIGHT","3"="COORS LIGHT","4"='MILLER LITE',"5"="NATURAL LIGHT")
for (i in 1:5) {
df2 <- beer_markets
df2 <- df2 %>% group_by(hh)
df2 <- df2 %>% summarise(
"BUD LIGHT" = sum(brand == "BUD LIGHT"),
)
df <- mutate(df, "BUD LIGHT" = df2$"BUD LIGHT")
}
`
Basically i want to replace every instance of "BUD LIGHT" inside of the loop with the dictionary value of beer[i] so that i can mutate through all 5 of the variables with just one loop
I tried
beer <- c("1"="BUD LIGHT","2"="BUSCH LIGHT","3"="COORS LIGHT","4"='MILLER LITE',"5"="NATURAL LIGHT")
for (i in 1:5) {
df2 <- beer_markets
df2 <- df2 %\>% group_by(hh)
df2 <- df2 %\>% summarise(
beer[i] b = sum(brand == beer[i]),
)
df <- mutate(df, beer[i] = df2$beer[i])
}
I was expecting it to use the value of beer[i] but it ended in error