# Selecting every n-th element from a list

I have a list:

data = {4, 5, 7, 8, 9, 5, 3, 2, 1, 2, 13, 12};


I want to take those elements in the list which are located at equal distances, say, every third element, getting the list {7, 5, 1, 12}. Can anyone suggest a way of doing this for a list having large number of elements.

• l[[n;;-1;;n]] ? – Dr. belisarius Oct 24 '14 at 16:28
• Could you please explain how does it work? – Suro Oct 24 '14 at 16:47
• I would advice for solutions based on extended syntax, which are easier to understand than runes. – rhermans Oct 24 '14 at 16:49
• Now it becomes clear. Thank you everyone for your prompt handling. – Suro Oct 24 '14 at 16:53

Please look up Part and Span.

You can use

data[[ ;; ;; n]]

• This is one of those questions that are easily answered using the documentation and should be closed as such, but at the same time would probably be really useful for new users (if only for the clear question title). – Yves Klett Oct 24 '14 at 19:10
• @YvesKlett: Could you link to where you found this easily in the documentation? – orome Oct 3 '15 at 19:48
• @ raxacoricofallapatorius Fifth entry in reference.wolfram.com/language/ref/Span.html – Yves Klett Oct 4 '15 at 8:46
• Having looked through the documentation, I didn't find it, only after finding this question, I knew what to look for. – gyger Feb 6 '16 at 10:39
• @YvesKlett - Out of the hundreds of names for functions, how are we supposed to know that 'span' is what we're looking for? I mean, it doesn't even have a name, it's like part of the list syntax. – Quarkly Jun 14 '20 at 19:20

I'm surprised that this has not come up:

Last /@ Partition[data, 3]


Before Span (and version 6), I used it a lot.

As well as Part an Span, you could also use Take.

data = {4, 5, 7, 8, 9, 5, 3, 2, 1, 2, 13, 12};
data[[3 ;; -1 ;; 3]]
Take[data, {3, -1, 3}]


Both give

{7, 5, 1, 12}


Downsample[array, n ] returns a downsampled version of the array by sampling every n'th element.

Downsample[data, 3]


{4, 8, 3, 2}

Partition with offset

Flatten @ Partition[data, 1, 3]


{4, 8, 3, 2}

• Introduced in version 9 and I discover it only now. Definitely the most direct implementation of the answer the OP wanted. – Michael Stern Mar 8 '20 at 13:44

data = {4, 5, 7, 8, 9, 5, 3, 2, 1, 2, 13, 12}


Let's say you want every third starting by the second element, that means you want parts {2, 5, 8, 11}. we get those indexes using Range

Range[2, Length[data], 3]

{2, 5, 8, 11}


Now we use this indexes with Part

Part[data, Range[2, Length[data], 3]]

{5, 9, 2, 13}


Lots of other great answers here but this is another way

Table[data[[i]], {i, 3, Length@data, 3}]


You can use

data = {4, 5, 7, 8, 9, 5, 3, 2, 1, 2, 13, 12};
sel = Partition[Range[3, Length@data, 3], 1]
Extract[data, sel]


But I'm sure there are shorter ways.