Inference from tables by joining reshaping and aggregating