I have a dataset from a survey that has several similar variables due to the way the survey had to be set up. For instance, I have 20 different variables for the price of medium soda in 2016. A facility only has a response on one medium soda question (it depended on the type of facility they were). I would like to add these together in R to get one medium soda variable for all facilities. An example of what the data looks like is below.
Q5a_MediumSoda_Coffee: 2.25, 3.35, NA, NA, NA, NA, NA...
Q6a_Mediumsoda_Burgers:NA,NA, 2.50, NA, NA, NA, NA...
Q7a_MediumSoda_Thai:NA,NA,NA,NA,2.30, 1.50, 2.75..
I attempted to combine all these variables into one by adding them together:
MediumSoda2016<-sum(Q5a_16_MedS_FSCoff+Q7a_16_MedS_FSAsian+Q9a_16_MedS_FSAmer+Q11a_16_MedS_FSDeli+Q13a_16_MedS_FSMex+Q15a_16_MedS_FSPizza+Q17a_16_MedS_FSPub+Q19a_16_MedS_FSBurgers+Q21a_16_MedS_FSItalian+Q23a_16_MedS_FSBBQRibs+Q25a_16_MedS_FSSeafood+Q27a_16_MedS_FSMed_Greek+Q29a_16_MedS_FSIndian+Q31a_16_MedS_FSOther, na.rm=TRUE)*
However, I get the following error:
Error in Q5a_16_MedS_FSCoff + Q7a_16_MedS_FSAsian + Q9a_16_MedS_FSAmer + :
non-numeric argument to binary operator
I checked and all variables are numeric so I assume it is an issue with the sum function (and I am using the wrong function), but cannot seem to figure out what code to use. My hope is to combine all of these so I have one column of medium soda data with prices for each facility in this column. Any help would be greatly appreciated.