Optimizing the function in R by replacing for loop
I have tried this, but I don't know, how much (and even if) faster it is. Anyway, you used a lot of redundant code (creating variables M, h_unbiased, delta_t etc.).

filter2 &lt;- function(x, m, delt) {
  series &lt;- x
  tau_crit &lt;- 3 # critical period (hours)
  theta_crit &lt;-  2*pi*delt/tau_crit # critical frequency
  # get the lanczos coefficients
  h &lt;- sapply(-m:m, FUN=function(x)ifelse(x == 0,theta_crit*delta_t/pi, 
    (sin(x*theta_crit*delt)/(pi*x)) * (sin(x*pi/m)/(x*pi/m))))
  # need to adjust the weights so that they add up to 1
  h &lt;- h/sum(h)
  # step through each time for which we'd like to create a filtered value
  y2 &lt;- sapply((1+m):(length(series)-m), function(t){
    sum(unlist(sapply(-m:m, FUN=function(x)(series[t+x]*h[m+x+1]))))
  })
  # return
  return(y2)
}