The resistor simply serves to limit the current to or from the pin in case something goes wrong. If your AVR decides to output high on the pin that something else wants to low (or vice versa), large, damaging currents may occur if not limited by some resistance. The current limit for the AVR is about 20 milliamps, and given that voltages are usually 5 V, something larger than 250 ohms should work.
To provide a margin of safety, 1-10k is an excellent choice; for digital signals, this rarely matters unless you are using high-speed applications (in any case, other than AVR capabilities). For analog inputs, it is advisable to use a similar resistor, since the amount of current that the ADC receives per sample is negligible if your resistor is in the range of several kilograms.
source share