I'm trying to convert date field of 3 datasets using for loop and got the error:
Error in as.Date.default(mydatasets[i]$Date, "%Y-%m-%d") : do not know how to convert 'mydatasets[i]$Date' to class “Date”
Here's the code:
papel_BBD <-read.csv("http://ichart.finance.yahoo.com/table.csv?s=BBD",sep=",", header=1)
papel_HSBC <-read.csv("http://ichart.finance.yahoo.com/table.csv?s=HSBC",sep=",", header=1)
papel_ITAU <-read.csv("http://ichart.finance.yahoo.com/table.csv?s=ITUB",sep=",", header=1)
mydatasets <- c(papel_BBD, papel_HSBC, papel_ITAU)
for (i in 1:length(mydatasets)) {
mydatasets[i]$Date <- as.Date(mydatasets[i]$Date, "%Y-%m-%d")
}
Console:
for (i in 1:length(mydatasets)) {
mydatasets[i]$Date <- as.Date(mydatasets[i]$Date, "%Y-%m-%d")
}
Error in as.Date.default(mydatasets[i]$Date, "%Y-%m-%d") : do not know how to convert 'mydatasets[i]$Date' to class “Date”
I think I'm missing something in this line inside the for loop:
mydatasets[i]$Date <- as.Date(mydatasets[i]$Date, "%Y-%m-%d")
Thanks