I imported some objects as follows, in this example I put only two, but I want to work with many, so I need to automate the processes a little:
library(quantmod)
#escolhendo a data que deseja
start <- as.Date("2014-01-01")
end<- as.Date("2018-01-12")
#primeiro termo refere a quais ativos vc quer baixar
#segundo de onde vc quer
#terceiro a data inicial
#quarto a data final
getSymbols(ativos, src = "yahoo", from = start, to = end)
After importing the objects, I need to transform them to data.frame
and change their headers to a for
, but I can not call each object in each iteration.
Iwouldliketochangealltheheadersinafor
,aswellastransformallindata.frame
toafor
,butIcannotcalleachobjectineachiteration.
Itriedtodothisbutitdidnotwork:
#cabeçalhodosativosimportadoscabecalho<-c("abertura","máxima", "mínima", "fechamento", "volume", "ajuste")
ativos2<-list(BVSP,PETR4.SA)
for(i in 1:NROW(ativos2)){
colnames(ativos2[i])<-cabecalho
}
As suggested by the colleague in the re-comment this is as follows
for(i in 1:NROW(ativos2)){
colnames(ativos2[[i]])<-cabecalho
}
And the following error appears
Error in colnames<-
( *tmp*
, value = header):
attempt to set 'colnames' on an object with less than two dimensions