How to properly apply `fft` function to some of the columns in a dataframe?

36 Views Asked by At

I'm trying to apply fft function to some columns of a dataframe that starts with 'EE'. I have a dataframe with 100000 rows and 119 columns; 3-92 cols will be used for calculation.

head(LiC13j_w20_dat_dat2)
# A tibble: 6 × 119
  chr     start EE85759 EE85761 EE85765 EE85769 EE85772 EE85773 EE85774 EE85777 EE85781 EE85785 EE85786 EE85788 EE85789 EE85790 EE85793 EE85794 EE85798 EE85799
  <chr>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
1 chr4   1.55e8       0      -1       1      -1       0      -1      -5      -2      -1       1       1      -2      -1      -1      -1      -6      -3      -1
2 chr6   1.38e8       0      -2       0      -2      -4      -8      -4      -2      -1      -2      -1      -2      -1      -4       0       0       0      -1
3 chr11  7.37e7       0      -3      -2      -1      -1      -3       0      -1      -5      -1      -1       0      -3      -3      -1      -2      -1      -1
4 chr1   1.88e8      -2       0       2      -5       1      -2       0      -3       0       0      -3       0      -1       0      -2       1       1      -1
5 chr2   1.99e8      -1       1      -1      -2      -5      -1       0      -4       3       1      -5       3      -3      -1      -1       0      -2      -2
6 chr5   1.66e8      -1      -3      -1      -3      -2      -3      -1      -2      -2      -1      -5      -1      -1      -1      -2      -4      -1      -3

Using below script,

for(i in 3:92) {      
  log_read <- fft(LiC13j_w20_dat_dat2[, i])
  LiC13j_w20_dat_dat2$fft[i] <- log_read
}

Or,

for (i in names(LiC13j_w20_dat_dat2)[grep("EE", names(LiC13j_w20_dat_dat2))]){
  LiC13j_w20_dat_dat2[, paste0(i, "_fft")] <- fft(LiC13j_w20_dat_dat2[ , i] )
}

However, getting an error that

Error in fft(LiC13j_w20_dat_dat2[, i]) : non-numeric argument
0

There are 0 best solutions below