Strange behavior from lag() skipping over certain rows