--- title: "Pop quiz!" author: "Luce" date: '2022-04-18' output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ## Accessing vectors ```{r set_up_colors_vector} my_colors <- c("red", "orange", "yellow", "green", "blue", "indigo", "violet") ``` - How can I find how many elements in my `my_colors` vector? ```{r} ``` - How do I get the 7th element of `my_colors`? ```{r} ``` - How can I check if one of the elements is "indigo"? - How do I check if the 7th element is "indigo"? - How can I change the element whose value is "indigo" to "purple", regardless of which position it's in? ## Named elements - What does `names()` do? - What does it return? - What does it do if your vector does not have named elements? ## Vector operations - How does x - 9:x work? - `0:10 / 10` yields the same result as `seq(from = 0, to = 1, by = 0.1)`. ```{r} 0:10 / 10 seq(from = 0, to = 1, by = 0.1) ``` Can you understand why? Which do you think is more efficient?