Filtering unique non-consecutive factors

I need to filter a very large data frame to remove repeating factor levels. The issue is that factor levels may repeat, as long as they are not consecutive. Filtering unique factor levels is very easy, but I need a method that keeps non-consecutive replicate factor levels.

For example, consider the vector A, A, A, B, B, A, C, C, C, C, B, B, B.

I need to filter that down to A, B, A, C, B.

This would ultimately be applied to a data frame in which rows are kept, but for simplicity, the concept/question applies to a vector.

I am guessing this is easier than I think it is, but any ideas are welcome!

vec_1 <- c("A", "A", "A", "B", "B", "A", "C", "C", "C", "C", "B", "B", "B")
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.