The post you link explains pretty well, but it does not explain how they selected the 2K resistor.
They do explain why, though. At the end of the question:
Since the Raspberry Pi GPIO PINs work with 3.3V, I had to build a voltage divider to convert the 5V output of the sensor to 3.3V. Assuming the left-most resistor on the breadboard is 2K ohm and the right-most resistor is 1K ohm, did I do right?
The sensor outputs its signal with 5V, but connected to a 3.3V input PIN on the Pi. Without knowledge of electronics, this is basically like fitting a triangle shape into a round hole---they don't match. To make that work, they introduce a voltage divider. This is typical pattern in electronics of this type, to divide a higher voltage into a lower voltage (the way around is another pattern).
So how do we divide voltage? This is where electronics knowledge comes into play. And this is very common and basic (basic, because it is usually taught in high school, but it can be far away in the past :-) ), so Wikipedia is a great place to search. The entry on voltage divider just saves the day. The whole entry is a good read if you intend to keep on playing with electronics. The salient part here is basically the image and the formula. The image shows the divider connects a resistor to the ground. The why can be seen through deriving the formula:
Current flows like water through the circuit, and the connection to the ground is necessary to avoid leaking (well, to get it to actually work). To derive the formula we basically use current and relations like
U = R・I.
The 2K comes from the target. The input is
Vin = 5V, and we want
Vout=3.3V. Using the formula above, we just need to find a pair of resistor values to get the right output. Usually, we fix one, say
R1, to a common available resistor. Let's pick 1K and we can calculate that
R2 should be 2K.
I hope this helps. For more information, I would suggest the Electrical Engineering section on StackExchange. This section on the Pi is best for questions specific to the Pi.