I understand, from Calculating the mean of a list with NaN values, that one can preserve structured data with missing values, and still calculate a mean, using Mean[DeleteMissing[]]
. I want to extend that to a vector, or list of lists. The Mean
function handles list of lists that don't have missing values just fine.
obs1 = {2,3,1,7};
obs2 = {1,1,2,1};
Mean[{obs1,obs2}]
Results
{3/2, 2, 3/2, 4}
And removing missing values to calculate a scalar mean is straightforward
list1 = {Missing[], 2, 3, Missing[], 6};
Mean[DeleteMissing[list1]]
Results
11/3
However, I haven't been able to figure out how to perform the analogous calculation for a vector.
list1 = {Missing[], 2, 3, Missing[], 6};
list2 = {4, Missing[], 1, Missing[], 1};
listOfLists= {list1,list2};
Mean[DeleteMissing[listOfLists]]
Mean[DeleteMissing[listOfLists,2]]
Results
{1/2 (4 + Missing[]), 1/2 (2 + Missing[]), 2, Missing[], 7/2}
{3, 2, 7/2}
The first attempt fails to ignoring the missing values (they aren't deleted), and the second result completely distorts the intended calculation by losing the structure of the data because the missing values are deleted.
The documentation for `Mean' states
$$ \text{Mean}\left[\left\{\left\{x_1,y_1,\ldots \right\},\left\{x_2,y_2,\ldots \right\},\ldots \right\}\right] \text{ gives } \left\{\text{Mean}\left[\left\{x_1,x_2,\ldots \right\}\right],\text{Mean}\left[\left\{y_1,y_2,\ldots \right\}\right]\right\} $$
So it seems to me that what I want to do is to have DeleteMissing
occur after the list of lists has been restructured, but before calculating the means of the individual lists.
What would be an efficient way to do this?
Edit/Update: The solution I'm looking for would produce either {4,2,2,Missing[],7/2}
or {4,2,2,7/2}
, in which case I would figure out separately which values were completely missing.