Import stock prices

stocks <- tq_get(c("CMG", "GM", "LULU"),
                 get = "stock.prices",
                 from = "2016-01-01",
                 )
stocks
## # A tibble: 6,567 × 8
##    symbol date        open  high   low close    volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 CMG    2016-01-04  9.37  9.38  8.95  8.98 134515000     8.98
##  2 CMG    2016-01-05  9     9.20  8.94  8.98 108065000     8.98
##  3 CMG    2016-01-06  8.76  8.94  8.46  8.53 182345000     8.53
##  4 CMG    2016-01-07  8.30  8.50  8.23  8.32  94600000     8.32
##  5 CMG    2016-01-08  8.40  8.53  8.23  8.27  64860000     8.27
##  6 CMG    2016-01-11  8.33  8.40  8.13  8.22  73125000     8.22
##  7 CMG    2016-01-12  8.31  8.42  7.98  8.09  82920000     8.09
##  8 CMG    2016-01-13  8.16  8.65  8.13  8.57 177625000     8.57
##  9 CMG    2016-01-14  8.94  9.27  8.73  9.09 188495000     9.09
## 10 CMG    2016-01-15  8.82  9.53  8.82  9.52 165385000     9.52
## # ℹ 6,557 more rows

Plot stock prices

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

Filter Rows

stocks %>% filter(adjusted > 4)
## # A tibble: 6,567 × 8
##    symbol date        open  high   low close    volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 CMG    2016-01-04  9.37  9.38  8.95  8.98 134515000     8.98
##  2 CMG    2016-01-05  9     9.20  8.94  8.98 108065000     8.98
##  3 CMG    2016-01-06  8.76  8.94  8.46  8.53 182345000     8.53
##  4 CMG    2016-01-07  8.30  8.50  8.23  8.32  94600000     8.32
##  5 CMG    2016-01-08  8.40  8.53  8.23  8.27  64860000     8.27
##  6 CMG    2016-01-11  8.33  8.40  8.13  8.22  73125000     8.22
##  7 CMG    2016-01-12  8.31  8.42  7.98  8.09  82920000     8.09
##  8 CMG    2016-01-13  8.16  8.65  8.13  8.57 177625000     8.57
##  9 CMG    2016-01-14  8.94  9.27  8.73  9.09 188495000     9.09
## 10 CMG    2016-01-15  8.82  9.53  8.82  9.52 165385000     9.52
## # ℹ 6,557 more rows

Arrange Rows

arrange(stocks)
## # A tibble: 6,567 × 8
##    symbol date        open  high   low close    volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 CMG    2016-01-04  9.37  9.38  8.95  8.98 134515000     8.98
##  2 CMG    2016-01-05  9     9.20  8.94  8.98 108065000     8.98
##  3 CMG    2016-01-06  8.76  8.94  8.46  8.53 182345000     8.53
##  4 CMG    2016-01-07  8.30  8.50  8.23  8.32  94600000     8.32
##  5 CMG    2016-01-08  8.40  8.53  8.23  8.27  64860000     8.27
##  6 CMG    2016-01-11  8.33  8.40  8.13  8.22  73125000     8.22
##  7 CMG    2016-01-12  8.31  8.42  7.98  8.09  82920000     8.09
##  8 CMG    2016-01-13  8.16  8.65  8.13  8.57 177625000     8.57
##  9 CMG    2016-01-14  8.94  9.27  8.73  9.09 188495000     9.09
## 10 CMG    2016-01-15  8.82  9.53  8.82  9.52 165385000     9.52
## # ℹ 6,557 more rows

Select Columns

select (stocks) ## Add Columns

Summarise with Groups

summaries_by(year, month, day)