Postgresql User Defined Aggregate Function In R