I have a real estate data
Reg Area Price
A 20 356
B 30 98
A 50 900
and I want to get
Reg Area Price AvgUnitPrice
A 20 356 17.9
B 30 98 3.26
A 50 900 17.9
For each region get all properties and calculate average price per unit area in that region and create new column with that value
e.g for region A we have
1. Area = 20, Price= 356 => Price per Area = 17.8
2. Area = 50, Price= 900 => Price per Area = 18
so avg price per unit area for region A becomes
(17.8 + 18) / 2 = 17.9
and then this value to all the region A properties