Start by loading the library and data.
library(dslabs)
data(murders)
1. Compute the per 100,000 murder rate for each state and store it in
an object called murder_rate
. Then use logical operators to create a
logical vector named low
that tells us which entries of murder_rate
are lower than 1.
2. Now use the results from the previous exercise and the function
which
to determine the indices of murder_rate
associated with values
lower than 1. Store your result in an object called low_ind
.
3. Use the results from the previous exercise to report the names of
the states with murder rates lower than 1. Store your result in an object
called low_states
.
4. Now extend the code from exercises 2 and 3 to report the states in
the Northeast region with murder rates lower than 1. Hint: use the previously
defined logical vector low
and the logical operator &
. Store your
result in an object called low_ne_states
.
5. In a previous exercise we computed the murder rate for each state
and the average of these numbers. How many states are below the average?
Store your result in an object called states_below_avg