Group Factor Levels in R (Example) | Combine into Same Category | Regroup, Modify, Change & Merge

preview_player
Показать описание
R code of this video:

x <- factor(c("a", "b", "a", "c", "c")) # Create example factor
x # Print example factor

x_new <- x # Duplicate example factor
levels(x_new) <- c("a", "b", "b") # Regroup factor levels
x_new # Print updated factor

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Thank you for this advice and all your videos!

nosuri
Автор

Hey Joachim, thank you so much for the nice video.😊I still have a quesion. I have a categorical variable questioning how person got his environmental knowldge and I have categories like (School, Media, Mass Media and so on) The problem is that the dataset shows every category as a separate binary category and I wanted to combine them all into one categorical variable.I do not know how to do it and I tried to apply this code in the video but I could not succeed :(

Thank you soo much

mahmoudmoustafamohammed
Автор

Hi, hope you can help me with this error:
I'm trying to combine a number of symbols into a group, for examples, the data is like this:
1. AF
2. AF
3. BI
4. BI
5. CP
6. CP
but I don't know why when I use the function levels(), the result is something like:
"CP" "AF" "BI"
It's not the order I wanted
Is there any way to fix the error? please help me, thank you.

lsjenny