I agree with c4757p. With a resistor, current flows from the high voltage side towards the low voltage side; and the "V" in the resistor formula (V = IR) refers to the relative voltage (i.e., the difference) across the resistor terminals.
If you want a source that alternates between 5V and "disconnected" state (also called "open", "high impedance", "Hi-Z", etc), there are many ways to achieve this -- have your function generator drive a transistor so that it switches on and off, and connect your resistor to 5V through the switch; use a diode to prevent the capacitor from discharging backwards through the resistor, etc.