It's pretty clear from the error message that dat$Date is not an appropriate time-based object.
Since dat$Date is created by the get_majorlandmarks() function, and your question provides no information about that, it's hard to be more specific. However, I would suggest looking at the output of class(dat$Date) and str(dat$Date) The results should indicate that dat$Date somehow indicates a time-based ordering. I wouldn't be surprised if dat$Date is a factor (the class() function will tell you if it is), in which case something is wrong with how dat is constructed. For example, there might be invalid values in an input file. The other thing is whether dates are acceptable to xts() for the order.by argument. I don't know. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 On 9/27/17, 2:31 PM, "R-help on behalf of istiyak ahamad" <r-help-boun...@r-project.org on behalf of istiyak....@gmail.com> wrote: Need Help in Debugging below script:-------------------------------- dat <- get_majorlandmarks(dat,Dmin,Per) fit_xts <- xts(dat$fit,order.by = dat$Date,frequency = 365) close_xts <- xts(dat$Close, order.by = dat$Date, frequency = 365 ) majorlandmarks_xts <-xts(dat$Close[dat$majorlandmarks==TRUE], order.by = dat$Date[dat$majorlandmarks==TRUE], frequency = 365 ) minorlandmarks_xts <- xts(dat$Close[dat$minorlandmarks==TRUE], order.by = dat$Date[dat$minorlandmarks==TRUE], frequency = 365 ) landmarkschart_data <- cbind(close_xts,fit_xts,majorlandmarks_xts,minorlandmarks_xts) Error:------------- order.by requires an appropriate time-based object dygraphs::dygraph(landmarkschart_data, xlab = "Time",ylab = "Price") %>% dySeries("..1",label = "Close", drawPoints = FALSE, strokeWidth = 1, color = "black") %>% dySeries("..2",label = "Fit", drawPoints = FALSE, strokeWidth = 1, color = "red") %>% dySeries("..3",label = "Major LandMarks", drawPoints = TRUE, pointSize = 5, strokeWidth = 0, color = "darkorange") %>% dySeries("..4",label = "Minor LandMarks", drawPoints = TRUE, pointSize = 1, strokeWidth = 0, color = "darkblue") %>% dyRangeSelector() ###Estimating error with different parameters # RMSE <- vector() # for(i in seq(0.01,0.1,0.01)){ # dat <- get_majorlandmarks(dat,i,0.01) # RMSE[i] <- sqrt(sum((dat$fit-dat$Close)^2)/nrow(dat)) # } # plot(RMSE) [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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.