[R] fft with NA values

Rolf Turner r.turner at auckland.ac.nz
Tue Sep 29 21:43:11 CEST 2009


On 29/09/2009, at 10:54 PM, Steve Jones wrote:

> Hi List,
>
> I'm trying to perform some spectral analysis on a time series, but  
> I've
> got a few data points missing, so they have NA values. Unfortunately,
> the fft function doesn't seem to like this, and gives a completely  
> empty
> result.
>
> Other than making up values to fill in the gaps, is there any way I  
> can
> get around this?
>
> Thanks in advance,
> Steve.
>
> PS I haven't spotted anything relevant in the man page, and as fft  
> is an
> internal function, I'll have to get the source code to figure out  
> what's
> going on. I'll do it if I must, but I'd rather not!

I'm curious.  Just what do you think the discrete Fourier transform of
a sequence of values containing missing values, should be?  Remember  
that
the fast Fourier transform is simply an algorithm for the efficient
*computation* of the discrete Fourier transform.

You can very easily write your own ``sft()'' (slow Fourier  
transform :-) )
function to calculate the DFT directly from the definition.  Unless your
data sequences are incredibly large, the speed difference between fft 
() and
sft() will not be noticeable. Into your sft() function you can place  
whatever
technique you think appropriate for handling missing values. It is  
not at all
clear to me that anything appropriate is possible.

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}




More information about the R-help mailing list