I like to run method="loess" on my data set and if errors, I like to try the lm method. Below is my code to do this, but it is still failing, any ideas?
df
Date Duration Athlete
1/1/2012 60 A
1/2/2012 30 A
1/3/2012 10 B
1/1/2012 5 C
1/2/2012 5 C
1/4/2012 4 C
ggplot(df, aes(Date, Duration, group=Athlete)) + geom_point(position="jitter", size=0.5) +theme_solarized(light = FALSE) + geom_smooth(method=ifelse(class(try(loess(Duration~Date, df)))=="try-error", "lm","loess"), se=T)
I get this error:
Error in simpleLoess(y, x, w, span, degree, parametric, drop.square, normalize, :
NA/NaN/Inf in foreign function call (arg 2)
In addition: Warning message:
In simpleLoess(y, x, w, span, degree, parametric, drop.square, normalize, :
NAs introduced by coercion
Error in function (el, elname) :