For these exercises we will use the US murders dataset. Make sure you load it prior to starting.
library(dslabs)
data("murders")
The function table
takes a vector and returns the frequency of
each element.
# The "c" in `c()` is short for "concatenate," which is the action of connecting items into a chain
# The function `c()` connects all of the strings within it into a single vector, which we can assign to `x`
x <- c("a", "a", "b", "b", "b", "c")
# Here is an example of what the table function does
table(x)
#> x
#> a b c
#> 2 3 1
You can quickly see how many states are in each region by applying this function.
table
function to make a table with the number of states per region.