I don't think that ordered=
parameter is doing what you think it is. When you set ordered=T
it creates an ordered factor which is analogous to an ordinal variable where as a regular factor behaves more like a categorical variable. It does not assume the vector is already ordered nor does it affect the sorting of the vector in any way.
If you want to specify a given order, you must use
frame$ID <- factor(frame$ID, levels=unique(frame$ID))
and then by
should behave as expected.