# 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.0648 Inform~ 175072270 USD
## 2 MSFT Microsoft~ 59491810 25881~ 0.0554 Inform~ 81470500 USD
## 3 AMZN Amazon.co~ 02313510 20000~ 0.0454 Consum~ 4500840 USD
## 4 FB Facebook ~ 30303M10 B7TL8~ 0.0221 Commun~ 25831024 USD
## 5 GOOGL Alphabet ~ 02079K30 BYVY8~ 0.0161 Commun~ 3226093 USD
## 6 GOOG Alphabet ~ 02079K10 BYY88~ 0.0158 Commun~ 3141612 USD
## 7 BRK.B Berkshire~ 08467070 20733~ 0.0153 Financ~ 20904160 USD
## 8 JNJ Johnson &~ 47816010 24758~ 0.0140 Health~ 28326900 USD
## 9 V Visa Inc.~ 92826C83 B2PZN~ 0.0125 Inform~ 18139536 USD
## 10 PG Procter &~ 74271810 27044~ 0.0123 Consum~ 26609918 USD
## # ... with 495 more rows
505 rows
8 columns
505 companies
Hint: Use the weight column of the data.
Apple, Microsoft and Amazon
Hint: Use the sector column of the data.
Health care, Financials, Information Technology, Industrials
Hint: Use the symbol column of the data.
NFLX
Hint: Insert a R code chunk below, type the following code: count(SP500, sector, sort = T)
Industrials has the largest the largest number of companies.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.