How to store complex tables and structures?
In third normal form 

IndvidualID
CatID
CaseID
Value   

Primary Key:  IndvidualID, CatID, CaseID

If you need to constrain CatID and/or CaseID then have a FK   

From that structure you can easily loop and create long format or multidimensional array.
It is also space efficient as a null is simply no row.

In sql an avg 

select CatID, avg(value)  
  from table 
 where CaseID = x 
 group by CatID  


Or you can just loop on those same constraints
Or a tool like LINQ