Averaging in difference equations driven by dynamical systems