Skip to main content
3 of 3
Replaced BlankSequence with Blank in the definition of datasetAverage
Michael Wijaya
  • 2.2k
  • 16
  • 30

This may be close to what you want:

datasetAverage[inputDataList_] := If[ Equal @@ Map[Length, inputDataList] == False, Print["DatasetAverage: Data sample sizes do not match"], Mean[inputDataList] ] 

Some sample inputs:

In[10]:= datasetAverage[{{1,2,3},{4,5,6},{7,8,9}}] Out[10]= {4,5,6} datasetAverage[{{1,2,3},{4,5,6,7}}] DatasetAverage: Data sample sizes do not match 

Edit

My earlier version of datasetAverage was defined using BlankSequence, but it did not make use of the fact that it can take an unspecified number of parameters. It is now rewritten using Blank.

Here is one version which uses BlankSequence:

datasetAverage2[inputDataList__] := If[ Equal @@ Map[Length, {inputDataList}] == False, Print["DatasetAverage: Data sample sizes do not match"], Mean[{inputDataList}] ] 

The only difference is that I now enclose every occurrence of inputDataList in parentheses.

In[9]:= datasetAverage2[{1,2,3},{4,5,6},{7,8,9}] Out[9]= {4,5,6} 
Michael Wijaya
  • 2.2k
  • 16
  • 30