[R] Non-numeric argument to fft

Uwe Ligges ligges at statistik.tu-dortmund.de
Sun Aug 31 17:06:37 CEST 2008



rkevinburton at charter.net wrote:
> If this is the case then how to I take a list of numbers (residuals in this case) and create anothe list that is longer and padded by zeros? Maybe fft already does this for me but as I understood it I need to pass an vector to the fft that is of a power of 2 length. If I still need to do this then is there something wrong with the code below?

spectrum() helps to make the intelligent tasks, but is sometimes too clever.

If you just want the fft, then you can pad as follows:

Replace the lines
   x <- as.numeric(rep(0,512))
   x <- merge(residuals(fit), x)

by something like
   x <- rep(0, 512)
   res <- residuals(fit)
   x[seq_along(res)] <- res



Uwe Ligges


> 
> Thank you.
> 
> Kevin
> 
> 
> ---- Uwe Ligges <ligges at statistik.tu-dortmund.de> wrote: 
>>
>> rkevinburton at charter.net wrote:
>>> I am calling fft and getting a "non-numeric" error:
>>>
>>> +         fit <- lm(Quantity ~ DayOfYear, .sublist)
>>> +         # Make the time series
>>> +         x <- as.numeric(rep(0,512))
>>> +         x <- merge(residuals(fit), x)
>>> +         # Transform range to -pi - pi
>>> +         x <- x - pi
>>> +         x <- x * (2 * pi)/(max(x) - min(x))
>>> +         fft(x) 
>>>
>>> Error in fft(x) : non-numeric argument
>>>
>>> How can I tell what the non-numeric argument is? There is only one argument.
>>>
>>> What am I doing wrong?
>>
>> I guess merge() does something different from what you expect and your x 
>> is a data.frame rather than a vector now....
>>
>> Uwe Ligges
>>
>>
>>
>>> Thank you.
>>>
>>> Kevin
>>>
>>>
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list