The above setup reads '1' when switch = off and '0' when switch = on
\$R\$ is an external pull-up resistor that avoids the floating of input in case the digital IO pin of the controller has no internal pull-up. In this case, it will pull the pin to 5V when switch = off.
The above setup reads '1' when switch = on and '0' when switch = off
\$R\$ is an external pull-down resistor here.
With a little bit of googling, you find myriad of tutorial on this topic, like this "official" one: https://www.arduino.cc/en/tutorial/button
The resistor is used to "park" the input reading to a default level when the button is released. If implemented as pull-down, it parks the input low (read = 0) and high (read = 1) when in a pull-up configuration. Without the resistor, the input is left floating which can lead to undesired behaviors if noise couples into the input (technically won't happen to you if you're just implementing a push-button circuit but on very crowded circuit application, noise sources won't come missing).
To go further and if your application need to accurately measure the time of "press", I would recommend searching for button "debounce" which can be implemented either in hardware or software. You could look here to start with: http://dduino.blogspot.com/2012/03/arduino-button-debouncing.html