You just need to add na.rm=TRUE
to your apply call.
apply(df,2,max,na.rm=TRUE)
Note: This does assume every column has at least one data point. If one does not sum
will return 0
.
EDIT BASED ON COMMENT
fft
does not have an na.rm
argument. Therefore, you will need to write your own function.
apply(df,2,function(x){fft(x[!is.na(x)])})
For example:
df <- data.frame(matrix(5,5,5))
df[,3] <- NA
> df
X1 X2 X3 X4 X5
1 5 5 NA 5 5
2 5 5 NA 5 5
3 5 5 NA 5 5
4 5 5 NA 5 5
5 5 5 NA 5 5
> apply(df,2,function(x){fft(x[!is.na(x)])})
$X1
[1] 2.500000e+01+0i 1.776357e-15+0i 1.776357e-15+0i 1.776357e-15+0i
[5] 1.776357e-15+0i
$X2
[1] 2.500000e+01+0i 1.776357e-15+0i 1.776357e-15+0i 1.776357e-15+0i
[5] 1.776357e-15+0i
$X3
complex(0)
$X4
[1] 2.500000e+01+0i 1.776357e-15+0i 1.776357e-15+0i 1.776357e-15+0i
[5] 1.776357e-15+0i
$X5
[1] 2.500000e+01+0i 1.776357e-15+0i 1.776357e-15+0i 1.776357e-15+0i
[5] 1.776357e-15+0i