Let's say I have two different lists for which I want to compute the total
list1 = {1, Null, 2, Null}
list2 = {Null, Null, Null, Null}
For list1, I want the total to be 3, i.e. ignore the Null elements and add the numeric ones. For list2, I want the total to be a Null since all elements are Null. I achieve want I want for list1 with
In[255]:= Total[DeleteCases[list1, Null]]
Out[255]= 3
However, the same command applied to list2 returns 0
In[254]:= Total[DeleteCases[list2, Null]]
Out[254]= 0
On the other hand, using only Total does not work with list1
In[256]:= Total[list1]
Out[256]= 3 + 2 Null
but works for list 2
In[257]:= Total[list2]
Out[257]= 4 Null
I'd like a command that works for both lists because the list might look like list1 or list2 depending on a parametrization.