# 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.0641 Inform~   163143150 USD           
##  2 MSFT   Microsoft~ 59491810   25881~ 0.0555 Inform~    77178420 USD           
##  3 AMZN   Amazon.co~ 02313510   20000~ 0.0420 Consum~     4353632 USD           
##  4 FB     Facebook ~ 30303M10   B7TL8~ 0.0198 Commun~    24540038 USD           
##  5 GOOGL  Alphabet ~ 02079K30   BYVY8~ 0.0191 Commun~     3069006 USD           
##  6 GOOG   Alphabet ~ 02079K10   BYY88~ 0.0185 Commun~     2963248 USD           
##  7 TSLA   Tesla Inc  88160R10   B616C~ 0.0182 Consum~     7740993 USD           
##  8 BRK.B  Berkshire~ 08467070   20733~ 0.0144 Financ~    19866228 USD           
##  9 JPM    JPMorgan ~ 46625H10   21903~ 0.0133 Financ~    31116444 USD           
## 10 JNJ    Johnson &~ 47816010   24758~ 0.0131 Health~    26873280 USD           
## # ... with 495 more rows

Q1 How many rows does the data have?

505 rows

Q2 How many columns does the data have?

8 columns

Q3 How many companies are listed in S&P500 Index?

505 companies

Q4 What are the top three stocks that have the greatest influence on ups and downs in S&P500 Index?

Hint: Use the weight column of the data.

1.Apple(AAPL), 2.Microsoft(MSFT), and 3.Amazon(AMZN)

Q5 List four sectors that are represented in S&P500 Index.

Hint: Use the sector column of the data.

Information Technology, Financials, Health Care, and Consumer Discretionary

Q6 What is the symbol of Netflix?

Hint: Use the symbol column of the data.

NFLX

Q7 What sector has the largest represention in S&P500 Index in terms of number of stocks.

Hint: Insert a R code chunk below, type the following code: count(SP500, sector, sort = T)

count(SP500, sector, sort = T)
## # A tibble: 11 x 2
##    sector                     n
##    <chr>                  <int>
##  1 Information Technology    76
##  2 Industrials               73
##  3 Financials                65
##  4 Health Care               63
##  5 Consumer Discretionary    61
##  6 Consumer Staples          32
##  7 Real Estate               30
##  8 Materials                 28
##  9 Utilities                 28
## 10 Communication Services    26
## 11 Energy                    23

The Information Technology sector has the largest representation in the S&P500 Index in terms of number of stocks.

Q8 Hide the messages, but display the code and its results on the webpage.

Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.