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

arun smartpink111 at yahoo.com
Tue Jan 21 21:48:16 CET 2014


Hi,
Couldn't reproduce the error after running your code:
 d <- dcast(d, date ~ id, value.var="simple_return")
 dim(d)
#[1] 356   9
 sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plyr_1.8       quantmod_0.4-0 TTR_0.22-0     xts_0.9-7      zoo_1.7-10    
[6] Defaults_1.1-1 stringr_0.6.2  reshape2_1.2.2

loaded via a namespace (and not attached):
[1] grid_3.0.2      lattice_0.20-23


A.K.


On Tuesday, January 21, 2014 2:57 PM, rcse2006 <rcse2006 at gmail.com> 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 R-help mailing list