[datatable-help] Error in structure(ordered, dim = ns) : dims [product 1] do not match the length of object [0]

Matt Dowle mdowle at mdowle.plus.com
Tue Jan 21 22:07:18 CET 2014


Hello,
This mailing list is just for the data.table package.   You could try 
the [plyr] tag on Stack Overflow or look at the documentation for those 
packages to find out where support is for those packages.  You probably 
intended to post to r-help,  which is the level up in Nabble.  To post 
here, you have to join this list and see the welcome message that this 
is just about data.table. If that didn't work please let us know.
Matt

On 21/01/14 18:17, rcse2006 wrote:
> 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.
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>



More information about the datatable-help mailing list