# 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]] ? Commented Oct 24, 2014 at 16:28
• Could you please explain how does it work?
– Suro
Commented Oct 24, 2014 at 16:47
• I would advice for solutions based on extended syntax, which are easier to understand than runes. Commented Oct 24, 2014 at 16:49
• @Suren Did you follow the links from my answer and read the documentation? Commented Oct 24, 2014 at 16:49
• Now it becomes clear. Thank you everyone for your prompt handling.
– Suro
Commented Oct 24, 2014 at 16:53

## 7 Answers

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). Commented Oct 24, 2014 at 19:10
• @YvesKlett: Could you link to where you found this easily in the documentation? Commented Oct 3, 2015 at 19:48
• @ raxacoricofallapatorius Fifth entry in reference.wolfram.com/language/ref/Span.html Commented Oct 4, 2015 at 8:46
• Having looked through the documentation, I didn't find it, only after finding this question, I knew what to look for. Commented Feb 6, 2016 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. Commented Jun 14, 2020 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.

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. Commented Mar 8, 2020 at 13:44

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}


Your data

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.