I have a "tidy" dataframe and am trying to run a series of t-tests. The first column includes a series of food names. The next 3 columns include 0 or 1 values that specify the experimental condition. The last column includes the mean of the ratings of the particular food.
FoodName Var1 Var2 Var3 Mean
hotdog 0 1 0 4.5
burger 1 1 0 5.5
fries 0 0 1 4.0
soda 1 0 1 6.0
I would like to run t.tests comparing the mean values for different groups depending on the conditions. Here are some examples of the types of t.tests I'd like to run:
- comparing mean food score for all foods for which var1=0 to the mean food score for all foods for which var1=1
- comparing mean foods score for all foods for which var1=0 and var2=1 to those for which var1=1 and var2=0
Here's some pseudocode for the examples:
t.test(mean if var1=0, mean if var1=1)
t.test(mean if var1=0 and var2=1, mean if var1=1 and var2=0)
How do I do this in R?