I have a list f,


I want to sum the first 3 in this list and divide that value by 3 and append to a new list. Then repeat for the next three values. Then repeat...

So my final list will be,

  • 2
    $\begingroup$ Developer`PartitionMap[Mean, y, 3] $\endgroup$
    – Kuba
    Nov 20, 2015 at 13:55
  • $\begingroup$ closely related 28240, even more general: 4061 $\endgroup$
    – Kuba
    Nov 20, 2015 at 14:02

3 Answers 3


Mathematica tends to involve modifying the whole list until you get the thing you want rather than looping and contracting new lists.

This is how I would think about it:

y = {{a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l}}

Get rid of the inside lists


{a, b, c, d, e, f, g, h, i, j, k, l}

Divide lists up uses Partition


{{a, b, c}, {d, e, f}, {g, h, i}, {j, k, l}}

I'm assuming you're adding 3 elements and diving by three to get a mean? I'll use Mean.


{1/3 (a + b + c), 1/3 (d + e + f), 1/3 (g + h + i), 1/3 (j + k + l)}

( This is short for Map[Mean, Partition[Flatten[y],3]] )

Then to get each element wrapped in a list as in your answer:


{{1/3 (a + b + c)}, {1/3 (d + e + f)}, {1/3 (g + h + i)}, {1/ 3 (j + k + l)}}

( Alternatively List/@Mean/@Partition[Flatten[y],3] )

y = {{a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}}     
MovingAverage[y, 3][[;; ;; 3]]
Clear[a, b, c, d, e, f, g, h]

y = {{a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}};

Mean /@ Partition[Flatten @ y, 3]

enter image description here

  • $\begingroup$ You've put wrong output :) $\endgroup$
    – Kuba
    Nov 20, 2015 at 14:07
  • $\begingroup$ Indeed, hard to see :) $\endgroup$
    – eldo
    Nov 20, 2015 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.