'Approx(): Need at least two non-NA values to interpolate R

I am trying to use nnetar for some time series forecasting, and running into an issue when the data has repeating values (i.e. the same counts observed in a time period). To reproduce the error I have created a list of values and replaced the first 10 values with a 0:

dummy.ls <- runif(n=80)

for(i in 1:10)
  dummy.ls[i] <- 0

fit <- nnetar(dummy.ls, lambda=0)

When running the nnetar function I receive the following error:

Error in approx(idx, x[idx], tt, rule = 2) : 
  need at least two non-NA values to interpolate
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

I see similar errors in other questions, but unsure how to avoid the error?

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source