Open BissKuttner opened 5 years ago
In order to save the results from the mutate function you need to assign them back to a new variable (or the same variable). You are missing this first line:
dat <-
dat %>%
mutate( injury.fatality = Totalinjuries > 0 | Totalfatalities > 0,
drugs.alcohol = AlcoholUse_Drv1 == "Alcohol" |
AlcoholUse_Drv2 == "Alcohol" |
DrugUse_Drv1 == "Drugs" |
DrugUse_Drv2 == "Drugs" )
Im trying to recreate lab 9 and am not able to get the answer for question 4, "Of all of the accidents that result in injuries or fatalities, how often are alcohol OR drugs involved?"
This is the code I have entered and I have it all in one code block because the variables I created by mutating don't exist if I put
sum (dat$injury.fatality & dat$drugs.alcohol)/ sum (dat$injury.fatality)
in its own code block.
What am I doing wrong??