# Load packages
library(tidyquant)
library(tidyverse) # for count() function
# Import S&P500 Stock Index
SP500 <- tq_index("SP500")
SP500
## # A tibble: 505 x 8
## symbol company identifier sedol weight sector shares_held local_currency
## <chr> <chr> <chr> <chr> <dbl> <chr> <dbl> <chr>
## 1 AAPL Apple Inc. 03783310 20462~ 0.0669 Inform~ 176054060 USD
## 2 MSFT Microsoft~ 59491810 25881~ 0.0563 Inform~ 81927390 USD
## 3 AMZN Amazon.co~ 02313510 20000~ 0.0470 Consum~ 4526040 USD
## 4 FB Facebook ~ 30303M10 B7TL8~ 0.0233 Commun~ 25975924 USD
## 5 GOOGL Alphabet ~ 02079K30 BYVY8~ 0.0164 Commun~ 3244193 USD
## 6 GOOG Alphabet ~ 02079K10 BYY88~ 0.0160 Commun~ 3159212 USD
## 7 BRK.B Berkshire~ 08467070 20733~ 0.0151 Financ~ 21021260 USD
## 8 JNJ Johnson &~ 47816010 24758~ 0.0140 Health~ 28485600 USD
## 9 V Visa Inc.~ 92826C83 B2PZN~ 0.0123 Inform~ 18241136 USD
## 10 PG Procter &~ 74271810 27044~ 0.0122 Consum~ 26759018 USD
## # ... with 495 more rows
There are 505 rows in the data set
There are 8 columns in this data set
505 companies listed in the Index
The top three greatest influences are Apple at 6.69% Microsoft at 5.63% and Amazon at 4.7%.
Four Sectors are: Information Tech, Consumer Discretionary, Communication Services, and Health Care.
NFLX
count(SP500, sector, sort = T)
## # A tibble: 11 x 2
## sector n
## <chr> <int>
## 1 Industrials 73
## 2 Information Technology 71
## 3 Financials 66
## 4 Health Care 62
## 5 Consumer Discretionary 61
## 6 Consumer Staples 33
## 7 Real Estate 31
## 8 Materials 28
## 9 Utilities 28
## 10 Communication Services 26
## 11 Energy 26
Industrials has the largest represention in the S&P500 at 73.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.