Skip to Content

R check sort order in two lists

This is turning out to be bit of a challenge. I've three vectors x, y & z

x = c('a','b','c','d','f','m','n')
y = c('b','c','f')
z = c('b','a','n')

x is my superset. It specifies the order in which the elements a,b,c... etc should appear.
What I want to do is to be able to tell if a vector follows the same order that x has. For example, y has the same order as x. 'b' is before 'c' which in turn is before 'f'. However z is out of order as 'a' comes after 'b'. Is there a quick way to check this?

Thanks much in advance.