getSymbols() quantmod library doubt
Hello, Thanks for the interest, Enrico. It is below. R> R> tickers "AALR3.SA" "AGRO3.SA" "ALPA3.SA" "ALPA4.SA" "ALUP11.SA" "AMER3.SA" " AMOB3.SA" "ANIM3.SA" "ASAI3.SA" "AURE3.SA" "AZUL4.SA" "B3SA3.SA" " BAUH4.SA" "BAZA3.SA" "BBAS3.SA" "BBDC4.SA" "BBSE3.SA" "BDLL4.SA" " BEES3.SA" "BIDU34.SA" "BLAU3.SA" "BMOB3.SA" "BPAC11.SA" "BPAN4.SA" " BRAP4.SA" "BRFS3.SA" "BRKM5.SA" "BRSR6.SA" "BRST3.SA" "BSLI3.SA" " CBAV3.SA" "CEAB3.SA" "CEBR3.SA" "CMIG3.SA" "CMIG4.SA" "CMIN3.SA" " COPH34.SA" "CPFE3.SA" "CPLE6.SA" "CRPG5.SA" "CSAN3.SA" "CSED3.SA" " CSMG3.SA" "CSNA3.SA" "CSUD3.SA" "CXSE3.SA" "CYRE3.SA" ... R> R> getSymbols(tickers, src = "yahoo", from = start, to = end, maxgap = 10, auto.asign = TRUE) R> R> tickers <- mget(ls(pattern = paste(tickers, collapse = "|"))) R> R> names(tickers) [1] "AALR3.SA" "AFHI11.SA" "AGRO3.SA" "ALPA3.SA" "ALPA4.SA" "ALUP11.SA" [7] "AMER3.SA" "AMOB3.SA" "ANIM3.SA" "ASAI3.SA" "AURE3.SA" "AZUL4.SA" [13] "B3SA3.SA" "BAUH4.SA" "BAZA3.SA" *"BBAS3.SA <http://BBAS3.SA>" "BBAS3.SA_log_returns" "BBAS3.SA_mean_log" * [19] "BBAS3.SA_sd_log" "BBDC4.SA" "BBSE3.SA" "BBSE3.SA_log_returns" "BBSE3.SA_mean_log" "BBSE3.SA_sd_log" [25] "BDLL4.SA" "BEES3.SA" "BIDU34.SA" "BLAU3.SA" "BMOB3.SA" "BPAC11.SA" [31] "BPAN4.SA" "BRAP4.SA" "BRFS3.SA" "BRKM5.SA" "BRSR6.SA" "BRST3.SA" ... R> class(tickers$BBAS3.SA) [1] "xts" "zoo" R> colnames(tickers$BBAS3.SA) [1] "BBAS3.SA.Open" "BBAS3.SA.High" "BBAS3.SA.Low" "BBAS3.SA.Close" "BBAS3.SA.Volume" "BBAS3.SA.Adjusted" R> class(tickers$BBAS3.SA_log_returns) [1] "xts" "zoo" R> colnames(tickers$BBAS3.SA_log_returns) [1] "daily.returns" R> class(tickers$BBAS3.SA_mean_log) [1] "numeric" R> R> colnames(tickers$BBAS3.SA_mean_log) NULL (as expected) R> Therefore the list I get from the mget operation above contains several elements with different types, which may include even _sd_ columns as well. My objective is to get rid of the .SA suffix used for Brazilian stocks in all elements downloaded as well as their columns. I chose to put everything in a list and operate on it. TIA, -- Andr? Luiz Tietbohl Ramos, PhD. Em seg., 29 de dez. de 2025 ?s 10:25, Enrico Schumann <es at enricoschumann.net> escreveu:
On Mon, 29 Dec 2025, Andre Luiz Tietbohl Ramos writes:
Hello Eric, Thanks for the reply! Your answer was correct however the my problem was not explained correctly, my apologies to everyone. The issue is that once a list is built from the symbols that were
download
a mixed type list is formed, see below. R> class(tickers$VALE3.SA_sd_log) [1] "numeric" R> class(tickers$VALE3.SA) [1] "xts" "zoo" R> R> The VALE3 ticker has another list element as well: VALE3.SA_mean_log. This happens with a few of the symbols only thus the issue at hand seems
to
be removing the list "numeric" type elements. TIA, -- Andr? Luiz Tietbohl Ramos, PhD.
Could you please post a small, reproducible example (in plain
text)? Otherwise, it will be hard so see where your problem
lies.
kind regards
Enrico
Em seg., 29 de dez. de 2025 ?s 03:18, Eric Berger <ericjberger at gmail.com escreveu:
library(quantmod)
keepohlc <- function(x) {
ohlc <- c(".Open",".High",".Low",".Close")
iV <- sapply(ohlc, \(s) {grep(s,colnames(x))})
x[,iV]
}
getSymbols("MSFT")
head(MSFT)
MSFT.Open MSFT.High MSFT.Low MSFT.Close MSFT.Volume
MSFT.Adjusted
2007-01-03 29.91 30.25 29.40 29.86 76935100
21.12207
2007-01-04 29.70 29.97 29.44 29.81 45774500
21.08670
2007-01-05 29.63 29.75 29.45 29.64 44607200
20.96644
2007-01-08 29.65 30.10 29.53 29.93 50220200
21.17159
2007-01-09 30.00 30.18 29.73 29.96 44636600
21.19280
2007-01-10 29.80 29.89 29.43 29.66 55017400
20.98060
MSFT <- keepohlc(MSFT)
head(MSFT)
MSFT.Open MSFT.High MSFT.Low MSFT.Close
2007-01-03 29.91 30.25 29.40 29.86
2007-01-04 29.70 29.97 29.44 29.81
2007-01-05 29.63 29.75 29.45 29.64
2007-01-08 29.65 30.10 29.53 29.93
2007-01-09 30.00 30.18 29.73 29.96
2007-01-10 29.80 29.89 29.43 29.66
On Sun, Dec 28, 2025 at 11:51?PM Andre Luiz Tietbohl Ramos
<andreltramos at gmail.com> wrote:
Hello, I'm downloading quote data using the getSymbols() function. It works
very
well but downloads two additional columns for a few symbols, namely _mean_log and _sd_log. Therefore, the traditional 5 column OHLCV data frame has two more
columns
in some symbols. I move all downloaded symbols to a list in order to ease some required computation. At the same time, my routine depends on OHLCV data only. Thus, I need to have a new list discarding the additional columns that exist in some symbols on the current list. The symbols with the
"extra"
columns must be kept. However their additional columns must be
removed.
Could anyone suggest a solution to this problem, please? Thanks in advance for any help, -- Andre Luiz Tietbohl Ramos, PhD
-- Enrico Schumann Lucerne, Switzerland https://enricoschumann.net