but it doesn't take into account the positions in column 1
Sorry, I'm still not sure what you want (and it's a little diffficult to infer it from code which - as you state - doesn't work).
Are you saying the positions in column 1 are meant to represent indices in some sparse array, with all unspecified positions (such as 12498249..12512574, etc.) implicitly having a value of zero, or what?
I think it would help if you could come up with some simplified (but sufficient/complete) sample input (say using a window size of 3) together with the desired output values.