Postgres Window Function Filter In R