[R] How to troubleshoot issue with curve() function?

Benno Pütz puetz at mpipsykl.mpg.de
Thu Jun 26 00:43:09 CEST 2014


I’d start trying to understand the error message - it is actually pretty clear (see ?curve).
I suspect curve is not the function you want to use, rather something like

plot(data$arrival_time, dexp(data$arrival_time, rate=0.06), xlim = c(0,  60), type=‘l’, main = "Exponential distribution”)

assuming your arrival times lie in the specified window.

Just a wild guess though, as you didn’t provide data (see footer)

On 25 Jun 2014, at 23:02 , Lavrenz, Steven M <slavrenz at purdue.edu> wrote:

> I am trying to plot data that I imported with read. table using a Weibull distribution. Here's the code I used for importing the data:
> 
> data <- read.table(file =
> "C:/Users/Steven/OneDrive/Unfiled/Temp/phase2.csv", header = FALSE, sep = ",", dec = ".", col.names = c("cycle_time", "cycle_length", "red_time", "prot_green", "perm_green", "veh_count", "vc", "max_delay", "prot_occ", "perm_occ", "red5_occ", "gor", "ror", "arrival_time"), na.strings = "NA")
> 
> And here's my code for plotting:
> 
> curve(dexp(data(arrival_time), rate=0.06), from = 0, to = 60, main = "Exponential distribution")
> 
> I keep getting this error message:
> 
> Error in curve(dexp(data(arrival_time), rate = 0.06), from = 0, to = 60,  : 
>  'expr' must be a function, or a call or an expression containing 'x'
> 
> How to I begin to troubleshoot this? The only thing I can think of is that my variable of interest, "arrival_time", does contain a number of rows with blanks, but would that be the underlying cause? If so, can I get the function to ignore blank rows?
> 
> ______________________________________________
> R-help at 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.
> 



More information about the R-help mailing list