For these exercises we will use the US murders dataset. Make sure you load it prior to starting.
library(dslabs)
data("murders")
population
column, store the result in pop_min
. We expect you to use the following method:
$
operatorsort
function[
operatorPitfall
Like every function in R the sort function does not alter it’s parameters (the vector to sort), it only returns a new sorted vector. If you don’t store the returned vector or override the unsorted vector, your sorted vector will be lost. (e.g.
sorted <- sort(original)
)
Now instead of the smallest population size, find the index (=rownumber) of the entry with the smallest population size in the unsorted population size data. store the index in pop_min_index
.
Hint
You can use the same method described in question 1 using the
order
function instead ofsort
. As explained in 2.10 Sortingorder
will first sort the values and afterwards replace each value with it’s original index (index before sorting)
We can actually perform the same operation as in the previous
exercise (question 2) one single function which.min
. Write one line of code that
does this. Store your result in pop_min_index_wm
.
smallest_state
.