Sorry if this has been asked/answered but I couldn't find anything here or on Google, and for sorry for the poor wording of the title. Anyway, here's my question:
Given a set of points in $\mathbb{R}^2$, find the equation of a line such that half of the points on the plane lie on one side of the line, and half lie on the other side. If there are an odd number of points the line must go through one of the points, as well as split the remaining points in half. The odd number of points case is the only one in which our line may pass through a point.
For example, if we have a single point, the line simply goes through that point. If we have $2$ points, say on $(0,0)$ and $(0,2)$, the line might be defined by $y=1$ (though something like $y=2x+1$ would also work. For the purposes of this problem the line $x=0$ would not work). If we have $4$ points, $(0,1), (-1,0), (0,-1)$, and $(1,0)$, then the equation $y=x$ works.
A fairly naive solution would be to always return a line with the equation $y = c$, where $c$ is the median $y$ value of all of our points. This approach works on sets of points such that the median y value is unique, but not otherwise (as our line will now pass through more than a single point.).
How might I go about finding a general solution to this problem?