Reputation: 2233
Why do I get this error while applying fft
(Fast Fourier Transform) to a data frame? If I use the same function on each variable by itself there is no error.
df<-read.table(text="pregnant glucose blood skin INSULIN MASS DIAB AGE CLASS predict_probability
1 106 70 28 135 34.2 0.142 22 0 0.15316285
1 91 54 25 100 25.2 0.234 23 0 0.05613959
4 136 70 0 0 31.2 1.182 22 1 0.54034794
9 164 78 0 0 32.8 0.148 45 1 0.64361578
3 173 78 39 185 33.8 0.970 31 1 0.79185196
11 136 84 35 130 28.3 0.260 42 1 0.31927737
0 141 84 26 0 32.4 0.433 22 0 0.41609308
3 106 72 0 0 25.8 0.207 27 0 0.10460090
9 145 80 46 130 37.9 0.637 40 1 0.67061324
10 111 70 27 0 27.5 0.141 40 1 0.16152296
",header=T)
If I write fft(df$pregnant)
I get the needed results but I try to use it on the whole data frame fft(df)
I get this error:
Error in fft(df) : non-numeric argument
Upvotes: 1
Views: 2742
Reputation: 1795
Use only the numeric columns:
apply(df,2,function(x) fft(as.numeric(x)))
Upvotes: 1