stocks <- tq_get(c("TECH", "GOOG", "VZ", "NVDA"),
get = "stock.prices",
from = "2016-01-01",
)
stocks
## # A tibble: 6,748 × 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 TECH 2016-01-04 89.1 89.1 86.5 88.2 373900 84.0
## 2 TECH 2016-01-05 88.3 88.9 87 88.0 269000 83.7
## 3 TECH 2016-01-06 86.9 87.8 86.3 87.7 631600 83.5
## 4 TECH 2016-01-07 86.6 87.6 85.8 87.2 284700 82.9
## 5 TECH 2016-01-08 87.6 87.6 85.2 85.8 264600 81.6
## 6 TECH 2016-01-11 86.1 86.1 83.3 84.3 232200 80.2
## 7 TECH 2016-01-12 84.8 85.9 83.8 85.2 188500 81.1
## 8 TECH 2016-01-13 85.4 85.8 82.2 82.4 241000 78.4
## 9 TECH 2016-01-14 82.9 85.0 81.8 83.5 164300 79.5
## 10 TECH 2016-01-15 81.9 83.9 81.2 83.3 492000 79.3
## # … with 6,738 more rows
stocks %>%
ggplot(aes(x = date, y = adjusted, color = symbol)) +
geom_line()
stocks %>% filter(adjusted > 75)
## # A tibble: 2,819 × 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 TECH 2016-01-04 89.1 89.1 86.5 88.2 373900 84.0
## 2 TECH 2016-01-05 88.3 88.9 87 88.0 269000 83.7
## 3 TECH 2016-01-06 86.9 87.8 86.3 87.7 631600 83.5
## 4 TECH 2016-01-07 86.6 87.6 85.8 87.2 284700 82.9
## 5 TECH 2016-01-08 87.6 87.6 85.2 85.8 264600 81.6
## 6 TECH 2016-01-11 86.1 86.1 83.3 84.3 232200 80.2
## 7 TECH 2016-01-12 84.8 85.9 83.8 85.2 188500 81.1
## 8 TECH 2016-01-13 85.4 85.8 82.2 82.4 241000 78.4
## 9 TECH 2016-01-14 82.9 85.0 81.8 83.5 164300 79.5
## 10 TECH 2016-01-15 81.9 83.9 81.2 83.3 492000 79.3
## # … with 2,809 more rows
##Arrange Rows
stocks %>% arrange(open)
## # A tibble: 6,748 × 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 NVDA 2016-02-11 6.20 6.39 6.20 6.32 34014400 6.18
## 2 NVDA 2016-02-09 6.23 6.64 6.2 6.37 42537200 6.23
## 3 NVDA 2016-02-10 6.41 6.60 6.32 6.36 33580000 6.21
## 4 NVDA 2016-02-12 6.42 6.44 6.19 6.43 34081600 6.28
## 5 NVDA 2016-02-08 6.51 6.54 6.21 6.30 60885200 6.16
## 6 NVDA 2016-02-16 6.52 6.76 6.50 6.75 48535200 6.59
## 7 NVDA 2016-01-20 6.70 6.96 6.61 6.87 48118000 6.71
## 8 NVDA 2016-02-17 6.83 6.98 6.80 6.92 77146800 6.76
## 9 NVDA 2016-01-15 6.88 6.96 6.66 6.78 84145200 6.62
## 10 NVDA 2016-01-19 6.92 7.11 6.80 6.83 45714000 6.67
## # … with 6,738 more rows
##Select Columns
stocks %>% select(date, high)
## # A tibble: 6,748 × 2
## date high
## <date> <dbl>
## 1 2016-01-04 89.1
## 2 2016-01-05 88.9
## 3 2016-01-06 87.8
## 4 2016-01-07 87.6
## 5 2016-01-08 87.6
## 6 2016-01-11 86.1
## 7 2016-01-12 85.9
## 8 2016-01-13 85.8
## 9 2016-01-14 85.0
## 10 2016-01-15 83.9
## # … with 6,738 more rows
##Add Columns
stocks %>% select(date, high, open)
## # A tibble: 6,748 × 3
## date high open
## <date> <dbl> <dbl>
## 1 2016-01-04 89.1 89.1
## 2 2016-01-05 88.9 88.3
## 3 2016-01-06 87.8 86.9
## 4 2016-01-07 87.6 86.6
## 5 2016-01-08 87.6 87.6
## 6 2016-01-11 86.1 86.1
## 7 2016-01-12 85.9 84.8
## 8 2016-01-13 85.8 85.4
## 9 2016-01-14 85.0 82.9
## 10 2016-01-15 83.9 81.9
## # … with 6,738 more rows
mutate(stocks, gain = low)
## # A tibble: 6,748 × 9
## symbol date open high low close volume adjusted gain
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 TECH 2016-01-04 89.1 89.1 86.5 88.2 373900 84.0 86.5
## 2 TECH 2016-01-05 88.3 88.9 87 88.0 269000 83.7 87
## 3 TECH 2016-01-06 86.9 87.8 86.3 87.7 631600 83.5 86.3
## 4 TECH 2016-01-07 86.6 87.6 85.8 87.2 284700 82.9 85.8
## 5 TECH 2016-01-08 87.6 87.6 85.2 85.8 264600 81.6 85.2
## 6 TECH 2016-01-11 86.1 86.1 83.3 84.3 232200 80.2 83.3
## 7 TECH 2016-01-12 84.8 85.9 83.8 85.2 188500 81.1 83.8
## 8 TECH 2016-01-13 85.4 85.8 82.2 82.4 241000 78.4 82.2
## 9 TECH 2016-01-14 82.9 85.0 81.8 83.5 164300 79.5 81.8
## 10 TECH 2016-01-15 81.9 83.9 81.2 83.3 492000 79.3 81.2
## # … with 6,738 more rows
##Summarise With groups
stocks %>% summarise(volume)
## # A tibble: 6,748 × 1
## volume
## <dbl>
## 1 373900
## 2 269000
## 3 631600
## 4 284700
## 5 264600
## 6 232200
## 7 188500
## 8 241000
## 9 164300
## 10 492000
## # … with 6,738 more rows