Postgres Window Function Count In R