Yes, that will also work!
So your tq_get()
function seems to be importing stock data.
To unpack what seems to be going on, this first line appears to be a function to import stock data, with options given to specify what to import and from what date:
stocks<-tq_get(c("AMD", "VLGEA", "UL"), get = "stock.prices", from=2000-01-01)
The second chunk is doing much the same. The first line is specifying a vector of symbols - c("AMD", "VLGEA","UL")
- which is then "piped" into the first argument of tq_get()
. So, effectively, everything up to select()
is just repeating the above line. select()
is selecting the symbol, date and adjusted columns.
stockdata<-c("AMD", "VLGEA","UL") %>%
tq_get(get = "stock.prices", from = "2000-01-01")%>%
select(symbol, date, adjusted)
The next bit is taking the data from above (stockdata
, which is your imported stock data from AMD, VLGEA and UL containing the columns symbol, date and adjusted). head()
is taking the top 6 rows of the data, and then kable()
is formatting it as a table.
head(stockdata, n = 6 )%>%
kable(caption = "First six data points.")
Your dataframe contains data for AMD, VLGEA and UL, but your table only contains AMD because that data is in the first 6 lines.
If you would just like to see your data, consider some of these options:
head(stockdata) #this prints the top few lines
tail(stockdata) #this prints the bottom few lines
dplyr::glimpse(stockdata) #this is a different way to print the data
View(stockdata) #this lets you see the whole data set in an RStudio tab
To tabulate your data you will have to reduce it a bit as its very big (1648 observations would make a big table!). To pull the top 6 rows of each symbol, I'd suggest this pipeline:
stockdata %>%
group_by(symbol) %>%
slice_head(n = 6) %>%
knitr::kable(caption = "First six data points of each company.")
This prints:
Table: First six data points of each company.
symbol |
date |
adjusted |
AMD |
2000-01-03 |
15.500000 |
AMD |
2000-01-04 |
14.625000 |
AMD |
2000-01-05 |
15.000000 |
AMD |
2000-01-06 |
16.000000 |
AMD |
2000-01-07 |
16.250000 |
AMD |
2000-01-10 |
17.500000 |
UL |
2000-01-03 |
8.042123 |
UL |
2000-01-04 |
7.925084 |
UL |
2000-01-05 |
8.259480 |
UL |
2000-01-06 |
8.426676 |
UL |
2000-01-07 |
8.894826 |
UL |
2000-01-10 |
8.577147 |
VLGEA |
2000-01-03 |
1.709273 |
VLGEA |
2000-01-04 |
1.733808 |
VLGEA |
2000-01-05 |
1.733808 |
VLGEA |
2000-01-06 |
1.701095 |
VLGEA |
2000-01-07 |
1.701095 |
VLGEA |
2000-01-10 |
1.701095 |