From this previous post: enter link description here
I would like to calculate two function based on condition length
. When lst
argument is <=4
one function scale
and second function with lm
model when length
arguments > 4, I tried with:
lapply(lst, function (x) ifelse((sapply(lst,length)<=4)==T,scale,
(fit <- lm(x ~ poly(seq(1:length(x)), 5, raw=TRUE)))
(d <- resid(fit)-mean(resid(fit)))/sd(resid(fit))))
but there is an error:
Error in ifelse((sapply(lst, length) <= 4) == T, scale, (fit <- lm(x ~ : unused argument (d <- resid(fit) - mean(resid(fit))/sd(resid(fit)))
How can I to calculate the fit and the z.score of the residuals in the same function when the length is more then 4?
data
lst <- list(a=c(2.5,9.8,5.0,6.7,6.5,5.2,34.4, 4.2,39.5, 1.3,0.0,0.0,4.1,0.0,0.0,25.5,196.5, 0.0,104.2,0.0,0.0,0.0,0.0,0.0),
b=c(147.4,122.9,110.2,142.3))