我喜欢在我的数据集上运行 method="loess",如果出现错误,我喜欢尝试 lm 方法。下面是我执行此操作的代码,但它仍然失败,有什么想法吗?
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)
我收到此错误:
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) :