Skip to main content
added 2 characters in body; edited title
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

How todo I extract the element in the middle positionelement(s) of a given list?

How do I extract the middle elementselement(s) of a given list?

Here is some code that works, but seems a little too long:

extract[x_] := 
      Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}] & @ Median[Range[Length @ x]]]

Here is another, shorter routine, but for a list of even length, it only gives one value, not two. I think two values would be better for even lists:

extract[x_] := Part[x, Quantile[Range[Length @ x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

How to extract the element in the middle position of a list?

How do I extract the middle elements of a given list?

Here is some code that works, but seems a little too long:

extract[x_] := 
      Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}] & @ Median[Range[Length @ x]]]

Here is another, shorter routine, but for a list of even length, it only gives one value, not two. I think two values would be better for even lists:

extract[x_] := Part[x, Quantile[Range[Length @ x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

How do I extract the middle element(s) of a given list?

How do I extract the middle element(s) of a given list?

Here is some code that works, but seems a little too long:

extract[x_] := 
      Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}] & @ Median[Range[Length @ x]]]

Here is another, shorter routine, but for a list of even length, it only gives one value, not two. I think two values would be better for even lists:

extract[x_] := Part[x, Quantile[Range[Length @ x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

added 74 characters in body
Source Link

How do I extract the middle elements of a given list?

Here is some code that works, but seems a little too long:

extract[x_] := 
      Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}]&] & @ Median[Range[Length @ x]]]

Here is another, shorter routine, but for a list of even lengyhlength, it only gives one value, not two. I think two values would be better for even list.lists:

extract[x_] := Part[x, Quantile[Range[Length@x]Quantile[Range[Length @ x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

Here is some code that works but seems a little too long:

extract[x_] := 
  Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}]& @ Median[Range[Length @ x]]]

Here is another, shorter, but for a list of even lengyh, it only gives one value, not two. I think two values would be better for even list.

extract[x_] := Part[x, Quantile[Range[Length@x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

How do I extract the middle elements of a given list?

Here is some code that works, but seems a little too long:

extract[x_] := 
      Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}] & @ Median[Range[Length @ x]]]

Here is another, shorter routine, but for a list of even length, it only gives one value, not two. I think two values would be better for even lists:

extract[x_] := Part[x, Quantile[Range[Length @ x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

General cleanup
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Here is one samplesome code, that works but seems a little too long:

extract[x_] := 
  Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}]& @ Median[Range[Length@x]]]Median[Range[Length @ x]]]

Here is another, shorter, but for an evena list of even lengyh, it only gives one value, not two. I think two values would be better for even list.

extract[x_] := Part[x, Quantile[Range[Length@x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

Here is one sample code, seems a little too long:

extract[x_] := 
 Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}]& @ Median[Range[Length@x]]]

Here is another, shorter, but for an even list, it only gives one value, not two. I think two values would be better for even list.

extract[x_] := Part[x, Quantile[Range[Length@x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

Here is some code that works but seems a little too long:

extract[x_] := 
  Part[x, If[IntegerQ[#], {#}, {Floor[#], Ceiling[#]}]& @ Median[Range[Length @ x]]]

Here is another, shorter, but for a list of even lengyh, it only gives one value, not two. I think two values would be better for even list.

extract[x_] := Part[x, Quantile[Range[Length@x], 1/2]]

So is there concise, efficient code that will return two elements for a list of even length?

General cleanup
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259
Loading
Tweeted twitter.com/#!/StackMma/status/343278264560803841
Source Link
HyperGroups
  • 8.6k
  • 1
  • 26
  • 63
Loading