On 21/01/2014 22:45, William Dunlap wrote:
You probably want to use %w instead of %u.  On Linux 'man strftime' says
        %w     The day of the week as a decimal, range 0 to 6, Sunday being  0.
               See also %u.
        %u     The day of the week as a decimal, range 1 to 7, Monday being  1.
               See also %w.  (SU)
where "(SU)" means "according to the Single Unix specification" and the lack
of "(...)" after %w means it is in some year's ANSI C standard.   I assume 
Windows
does not attempt to subscribe to the Single Unix standard.

Maybe, but "%u" is in POSIX, standards Windows no long attempts to follow (and never did by default).

If you need "%u" on Windows, try R-devel. strftime has been replaced there (by default on Windows, optionally on other platforms) by a POSIX-2008-compliant version.


Bill Dunlap
TIBCO Software
wdunlap tibco.com


-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of William Dunlap
Sent: Tuesday, January 21, 2014 2:33 PM
To: arun; R help
Subject: Re: [R] [datatable-help] Error in structure(ordered, dim = ns) : dims 
[product 1]
do not match the length of object [0]

When I use R-3.0.2 on Windows 7 the %u descriptor for format.Date() always
gives "", while on Linux in gives as.character(day-of-the-week).  The resulting 
NA's
on Windows could be the source of your problem.

On Linux I get:
    > format(as.Date(c("2014-01-21", "2014-01-22", "2014-01-28")), "%u")
    [1] "2" "3" "2"
    > as.numeric(.Last.value)
    [1] 2 3 2
    > cat(version$version.string, "on", version$platform, "\n")
    R version 3.0.2 (2013-09-25) on x86_64-unknown-linux-gnu

while on Windows:
   > format(as.Date(c("2014-01-21", "2014-01-22", "2014-01-28")), "%u")
   [1] "" "" ""
   > as.numeric(.Last.value)
   [1] NA NA NA
   > cat(version$version.string, "on", version$platform, "\n")
   R version 3.0.2 (2013-09-25) on x86_64-w64-mingw32

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")

I you didn't reuse the same name, d, for the result of all these
steps it would be easier to poke through the intermediate
results to see where the trouble began (the output of subset()
is a 0-row data.frame and dcast() dies when its input has
zero rows).

Bill Dunlap
TIBCO Software
wdunlap tibco.com


-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of arun
Sent: Tuesday, January 21, 2014 12:48 PM
To: R help
Subject: Re: [R] [datatable-help] Error in structure(ordered, dim = ns) : dims 
[product 1]
do not match the length of object [0]

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 <rcse2...@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-h...@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--
Brian D. Ripley,                  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to