This will get you all the data for a specified stock list for a duration.
suppressPackageStartupMessages({
library(tidyquant)
library(tsibble)
})
indices <- c("AAPL","MSFT","AMZN","GOOGL","FB","TSM","TSLA","BABA","BRK.A","JPM","V","JNJ","WMT","MA","UNH","DIS","NVDA","BAC","HD","PG")
start_year <- "1996-01-01"
to_year <- "2016-12-31"
series <- tq_get(indices, get = "stock.prices", from = base_year, to = to_year)
then the tsibble package has tidyverse-like subsetting, can deal with irregular time series such as stock prices, and is the base class for a rich suite of time series and forecasting analytic tools. See the online text.