Postgresql Window Functions Count Distinct In R