[datatable-help] Error in structure(ordered, dim = ns) : dims [product 1] do not match the length of object [0]
rcse2006
rcse2006 at gmail.com
Tue Jan 21 19:17:08 CET 2014
Trying to run below 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
> 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.
--
View this message in context: http://r.789695.n4.nabble.com/Error-in-structure-ordered-dim-ns-dims-product-1-do-not-match-the-length-of-object-0-tp4683923.html
Sent from the datatable-help mailing list archive at Nabble.com.
More information about the datatable-help
mailing list