Vector selection by name
Another way to tackle the previous exercise is by using the names of the vector elements (Monday, Tuesday, ...) instead of their numeric positions. For example,
poker_vector["Monday"]
will select the first element of poker_vector since "Monday" is the name of that first element.
Just like you did in the previous exercise with numerics, you can also use the element names to select multiple elements, for example:
poker_vector[c("Monday","Tuesday")]
Instruction
- Select the first three elements in
poker_vectorby using their names:"Monday","Tuesday"and"Wednesday". Assign the result of the selection topoker_start. - Calculate the average of the values in
poker_startwith the mean() function. Simply print out the result so you can inspect it.