Future particle accelerators such as the the SLAC ``Linac Coherent Light Source-II'' (LCLS-II) and the proposed Cornell Energy Recovery Linac (ERL) require hundreds of superconducting radio-frequency (SRF) cavities operating in continuous wave (CW) mode. In order to achieve economic feasibility of projects such as these, the cavities must achieve a very high intrinsic quality factor (Q0) to keep cryogenic losses within feasible limits. To reach these high Q0's in the case of LCLS-II, nitrogen-doping has been proposed as a cavity preparation technique. When dealing with Q0's greater than 1\e{10}, the effects of ambient magnetic field on Q0 become significant. Here we show that the sensitivity to RF losses from trapped magnetic field in a cavity's walls is strongly dependent on the cavity preparation. Specifically, standard electropolished and 120∘C baked cavities show a residual resistance sensitivity to trapped magnetic flux of ∼0.6 and ∼0.8 nΩ/mG trapped, respectively, while nitrogen-doped cavities show a sensitivity of ∼ 1 to 5 nΩ/mG trapped. We show that this difference in sensitivities is directly related to the mean free path of the RF surface layer of the niobium: shorter mean free paths lead to less residual resistance sensitivity to trapped magnetic flux in the dirty limit (ℓ<<ξ0) while longer mean free paths lead to lower sensitivity in the clean limit (ℓ>>ξ0). These experimental results are also shown to have good agreement with recent theoretical predictions for pinned vortex lines oscillating in RF fields.