DS4PS / course_website

https://ds4ps.github.io/course_website/
0 stars 0 forks source link

Lab 9 Question 1 #15

Open tnlutes opened 5 years ago

tnlutes commented 5 years ago

I am finally able to bring the data set into my work, but now I am stumped on how to set up the answers using the dplyr functions. I have searched and found various ways to find the totals, but none of the functions I am using seem to work. Is there anyone who could show me how they answered this question? I'm not sure if it's my choice in dplyr functions or the way I'm setting up the data frame. Any help would be much appreciated. Thank you!

screen shot 2018-10-27 at 9 55 14 pm

lecy commented 5 years ago

If you are counting things are taking proportions, unless your data is already binary or T/F, the easiest way is typically to create a logical vector using a logical statement, then take a sum() or a mean() of the vector.

In this case you want to know how many crashes result in serious injury OR fatality. You just need to define a compound logical statement:

# pseudocode only
sum( injury > 0 | fatality > 0 )

https://ds4ps.github.io/Data-Science-Class/TEXTBOOK/docs/logical-statements.html#usefulness-of-selector-vectors