I have a dataframe:
levels counts 1, 2, 2 24 1, 2 20 1, 3, 3, 3 15 1, 3 10 1, 2, 3 25
I want to consider, for example, "1, 2, 2" and "1, 2" as one and the same. Therefore, as long as there is "1" and "2" without any other symbol, it will be considered the level of "1, 2". Here is the data frame you need:
levels counts 1, 2 44 1, 3 25 1, 2, 3 25
Here is the code to reproduce the original data frame:
df <- data.frame(levels = c("1, 2, 2", "1, 2", "1, 3, 3, 3", "1, 3", "1, 2, 3"), counts = c(24, 20, 15, 10, 25)) df$levels <- as.character(df$levels)