I have a set of data with a column of category and another column of subcategory. However, some of the category data is incorrect. I want to fix those incorrect category data based on subcategories.
For example, we have two categories: A and B with subcategories A_sub and B_sub. However, one of the entries for category is mistakenly input as "Others" but with a subcategory of "A_sub" (see code below). Is there any elegant way to change "Others" to "A" under the category column?
data <- data.frame("category" = c("A", "B", "B", "A", "Others", "Others"), "subcategory" = c("A_sub", "B_sub", "A_sub", "A_sub", "A_sub", "A_sub"))
The expected output is:
Thank you!