Error with "lowess" function in R

#1
I have a problem with lowess function to smooth time series NDVI (8-day image from apr to oct in Julian day) as a function of time by polynomial regression in R. Here is the scripts I run:

#Create a time vector to act as x
time<-sort(sample(97:297, nlayers(ndvi2000crop1)))

#locally-weighted polynomial regression of ndvi ~ time
t.lowess <- function(x,...) { if (is.na(x[1])) {NA} else {lowess(x,y,...)$y } }
f.pred <- calc(ndvi2000crop1, t.lowess)

When I calculate the function on image, an error appeared something like this "Error in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply): cannot use this function". Can you tell me where this error comes from in this part?

Thank you