Error in generation of graph in R

3

Hello,

I'm trying to create a chart from a list, but I'm not getting it.

The downloading part works perfectly:

    # download adj. price data - Asset[1],Asset[2]...
symbols= c("TIET4.SA","BVMF3.SA", "CCRO3.SA","ITUB4.SA","WIZS3.SA")

    Asset = list()
    for (symbol in symbols)
      Asset[[symbol]] = as.zoo(download_data(symbol, start_date, end_date))

When I try to generate the graph with this code:

# Visualiza gráficos da carteira
for(i in 1:length(symbols)){
  plot(Asset[i], main=asset1, col=2, xlab="Período",
       ylab="Preço",type="l")
}

I get the following error:

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' is a list, but does not have components 'x' and 'y'

I have seen some posts showing the same error, but I could not understand or reproduce the answers that were given. I'm not experienced in R!

Could someone help?

Thanks,

    
asked by anonymous 05.03.2018 / 00:32

1 answer

6

The object Asset is a list. To select each element in this list with% s of% you should use double brackets: i :

# Visualiza gráficos da carteira
for(i in 1:length(symbols)){
      plot(Asset[[i]], main=asset1, col=2, xlab="Período",
      ylab="Preço",type="l")
}
    
05.03.2018 / 00:46