We report on marked memory effects in the vortex system of twinned YBa2Cu3O7 single crystals observed in ac susceptibility measurements. We show that the vortex system can be trapped in different metastable states with variable degree of order arising in response to different system histories. The pressure exerted by the oscillating ac field assists the vortex system in ordering, locally reducing the critical current density in the penetrated outer zone of the sample. The robustness of the ordered and disordered states together with the spatial profile of the critical current density lead to the observed memory effects.