Import stock prices

stocks <- tq_get(c("LULU", "MSFT", "AAPL"),
                 get = "stock.prices",
                 from = "2021-01-01",
                 to = "2022-01-01")
stocks
## # A tibble: 756 × 8
##    symbol date        open  high   low close  volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl>
##  1 LULU   2021-01-04  352.  357.  346.  356. 2015300     356.
##  2 LULU   2021-01-05  358.  369.  357.  366. 2122900     366.
##  3 LULU   2021-01-06  362.  368.  357.  363. 1170800     363.
##  4 LULU   2021-01-07  367.  374.  365.  367. 1103000     367.
##  5 LULU   2021-01-08  367.  371.  363.  365.  994900     365.
##  6 LULU   2021-01-11  354.  373.  352.  362. 1754000     362.
##  7 LULU   2021-01-12  362.  362.  351.  357. 1628000     357.
##  8 LULU   2021-01-13  358.  359.  350.  352. 1108700     352.
##  9 LULU   2021-01-14  352.  358.  348.  348. 1047700     348.
## 10 LULU   2021-01-15  347   347.  337.  344. 1401200     344.
## # … with 746 more rows

Plot stock prices

stocks %>%
    
    ggplot(aes(x = date, y = adjusted, color = symbol)) +
    geom_line()

Apply the dplyr verbs you learned in chapter 5

Filter rows

stocks %>% filter(adjusted > 24)
## # A tibble: 756 × 8
##    symbol date        open  high   low close  volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>   <dbl>    <dbl>
##  1 LULU   2021-01-04  352.  357.  346.  356. 2015300     356.
##  2 LULU   2021-01-05  358.  369.  357.  366. 2122900     366.
##  3 LULU   2021-01-06  362.  368.  357.  363. 1170800     363.
##  4 LULU   2021-01-07  367.  374.  365.  367. 1103000     367.
##  5 LULU   2021-01-08  367.  371.  363.  365.  994900     365.
##  6 LULU   2021-01-11  354.  373.  352.  362. 1754000     362.
##  7 LULU   2021-01-12  362.  362.  351.  357. 1628000     357.
##  8 LULU   2021-01-13  358.  359.  350.  352. 1108700     352.
##  9 LULU   2021-01-14  352.  358.  348.  348. 1047700     348.
## 10 LULU   2021-01-15  347   347.  337.  344. 1401200     344.
## # … with 746 more rows

Arrange rows

Select columns

Add columns

Summarise with groups