You define a function called running.acf.max and then call plot(running.acf.max) R's plot, when given a function f, makes a plot of f(x) vs. x by calling curve().
Did you mean to plot the result of running.acf.max with its default arguments? That would be done with plot(running.acf.max()) There are several other problems with this code. E.g., you have running.acf.max <- function (data = returns, window = 100, nlags = 5, plot = T, main = "") { clevel <- qnorm(0.5 + 0.95/2)/sqrt(window) series <- rollapply(data = returns, window, align = "right", by = 1, function(w) { ... You should have data=data in the call to rollapply so it depends on the 'data' argument to running.acf.max. Use traceback() after an error to see where the error came from. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Mar 3, 2017 at 4:43 AM, Allan Tanaka <allantanak...@yahoo.com> wrote: > Please help. I try to re-produce R-script by plotting a set of functionWhen i > running code: plot(Vectorize(running.acf.max))it gets the error message like > this: Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = > ylab, : 'expr' did not evaluate to an object of length 'n' > Even though i have vectorized the function argument. > > ______________________________________________ > 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.