Does this work for you?
library(tidyquant)
library(tidyverse)
symb = tq_index("SP500")
for (i in(1:505)) {
tryCatch({
(
getSymbols(
symb$symbol[i],
from = '2017-01-01',
to = "2018-03-01",
warnings = FALSE,
auto.assign = TRUE
)
)
}, error = function(e) {
cat("ERROR :", conditionMessage(e), "\n")
})
}
stocknames <- ls(pattern = "[A-Z]{1,4}") %>%
set_names()
fusion <- map_dfc(stocknames, ~ as_tibble(eval(sym(.))))
fusion
#> # A tibble: 291 x 2,988
#> A.Open A.High A.Low A.Close A.Volume A.Adjusted AAL.Open AAL.High AAL.Low
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 45.9 46.8 45.7 46.5 1739600 45.3 47.3 47.3 46.1
#> 2 46.9 47.4 46.8 47.1 1821300 45.9 46.6 47.4 46.3
#> 3 47.0 47.1 46.4 46.5 1503700 45.3 46.5 46.9 45.6
#> 4 46.6 48.1 46.6 48.0 2883400 46.7 45.8 46.7 45.5
#> 5 48.0 48.6 47.9 48.1 2575300 46.9 46.0 47.3 45.8
#> 6 48.3 48.5 47.8 48.1 1560500 46.8 47 48.5 47.0
#> 7 48.0 49.5 48.0 49.2 5624300 48.0 49.3 49.9 48.1
#> 8 48.9 48.9 48.0 48.5 3276900 47.2 48.7 49 46.8
#> 9 48.6 48.8 48.4 48.7 1568500 47.4 48.2 48.4 47.5
#> 10 48.4 48.7 48.2 48.3 1938800 47.0 47.6 47.8 46.7
#> # … with 281 more rows, and 2,979 more variables: AAL.Close <dbl>,
#> # AAL.Volume <dbl>, AAL.Adjusted <dbl>, AAP.Open <dbl>, AAP.High <dbl>,
#> # AAP.Low <dbl>, AAP.Close <dbl>, AAP.Volume <dbl>, AAP.Adjusted <dbl>,
#> # AAPL.Open <dbl>, AAPL.High <dbl>, AAPL.Low <dbl>, AAPL.Close <dbl>,
#> # AAPL.Volume <dbl>, AAPL.Adjusted <dbl>, ABBV.Open <dbl>, ABBV.High <dbl>,
#> # ABBV.Low <dbl>, ABBV.Close <dbl>, ABBV.Volume <dbl>, ABBV.Adjusted <dbl>,
#> # ABC.Open <dbl>, ABC.High <dbl>, ABC.Low <dbl>, ABC.Close <dbl>,
#> # ABC.Volume <dbl>, ABC.Adjusted <dbl>, ABMD.Open <dbl>, ABMD.High <dbl>,
#> # ABMD.Low <dbl>, ABMD.Close <dbl>, ABMD.Volume <dbl>, ABMD.Adjusted <dbl>,
#> # ABT.Open <dbl>, ABT.High <dbl>, ABT.Low <dbl>, ABT.Close <dbl>,
#> # ABT.Volume <dbl>, ABT.Adjusted <dbl>, ACN.Open <dbl>, ACN.High <dbl>,
#> # ACN.Low <dbl>, ACN.Close <dbl>, ACN.Volume <dbl>, ACN.Adjusted <dbl>,
#> # ADBE.Open <dbl>, ADBE.High <dbl>, ADBE.Low <dbl>, ADBE.Close <dbl>,
#> # ADBE.Volume <dbl>, ADBE.Adjusted <dbl>, ADI.Open <dbl>, ADI.High <dbl>,
#> # ADI.Low <dbl>, ADI.Close <dbl>, ADI.Volume <dbl>, ADI.Adjusted <dbl>,
#> # ADM.Open <dbl>, ADM.High <dbl>, ADM.Low <dbl>, ADM.Close <dbl>,
#> # ADM.Volume <dbl>, ADM.Adjusted <dbl>, ADP.Open <dbl>, ADP.High <dbl>,
#> # ADP.Low <dbl>, ADP.Close <dbl>, ADP.Volume <dbl>, ADP.Adjusted <dbl>,
#> # ADS.Open <dbl>, ADS.High <dbl>, ADS.Low <dbl>, ADS.Close <dbl>,
#> # ADS.Volume <dbl>, ADS.Adjusted <dbl>, ADSK.Open <dbl>, ADSK.High <dbl>,
#> # ADSK.Low <dbl>, ADSK.Close <dbl>, ADSK.Volume <dbl>, ADSK.Adjusted <dbl>,
#> # AEE.Open <dbl>, AEE.High <dbl>, AEE.Low <dbl>, AEE.Close <dbl>,
#> # AEE.Volume <dbl>, AEE.Adjusted <dbl>, AEP.Open <dbl>, AEP.High <dbl>,
#> # AEP.Low <dbl>, AEP.Close <dbl>, AEP.Volume <dbl>, AEP.Adjusted <dbl>,
#> # AES.Open <dbl>, AES.High <dbl>, AES.Low <dbl>, AES.Close <dbl>,
#> # AES.Volume <dbl>, AES.Adjusted <dbl>, AFL.Open <dbl>, …
Created on 2020-02-22 by the reprex package (v0.3.0)