Trying to run R code to data frame getting error Error in structure(ordered, dim = ns

#1
Trying to run below code.

Code:
library(quantmod)
symbols <- c("AAPL", "DELL", "GOOG", "MSFT", "AMZN", "BIDU", "EBAY", "YHOO")
d <- list()
for(s in symbols) {
  tmp <- getSymbols(s, auto.assign=FALSE, verbose=TRUE)
  tmp <- Ad(tmp)
  names(tmp) <- "price"
  tmp <- data.frame( date=index(tmp), id=s, price=coredata(tmp) )
  d[[s]] <- tmp
}
d <- do.call(rbind, d)
d <- d[ d$date >= as.Date("2007-01-01"), ]
rownames(d) <- NULL

# Weekly returns
library(plyr)
library(reshape2)
d$next_friday <- d$date - as.numeric(format(d$date, "%u")) + 5
d <- subset(d, date==next_friday)
d <- ddply(d, "id", mutate,
           previous_price = lag(xts(price,date)),
           log_return    = log(price / previous_price),
           simple_return = price / previous_price - 1
)
d <- dcast(d, date ~ id, value.var="simple_return")
Getting error
Code:
> d <- dcast(d, date ~ id, value.var="simple_return")
Error in structure(ordered, dim = ns) : 
  dims [product 1] do not match the length of object [0]
Please help me how to use ddply and dcast or using other similar function to get same data.
 

Dason

Ambassador to the humans
#2
Re: Trying to run R code to data frame getting error Error in structure(ordered, dim

Take a look at what d looks like after you run this line:
Code:
d$next_friday <- d$date - as.numeric(format(d$date, "%u")) + 5
 
#3
Re: Trying to run R code to data frame getting error Error in structure(ordered, dim

Thanks Dason for your reply,

but i am getting error at this line of code

d <- dcast(d, date ~ id, value.var="simple_return")

Thanks