How to create multiple dummy variables without having to it manually for each catergory.

Hello, community,

I have a dataset with over 100 different countries. I would like to create a dummy variable for each. My challenge is that 100 countries are too much for me to create every single dummy manually. Is there a package or even command I can use to create all the 100 dummy variables at once?

Welcome to the community. To me it is not clear what exactly you want. Would you please tell me about your country dataframe (how many rows, columns, column names etc.) and expected output ? You can come up with some small example (reproducible example [Video] Reproducible Examples and the `reprex` package)to show what you want. sincerely,

f you are going to run a regression, create a variable that turns your country name into what r calls a factor. Then something like

lm(y~x + as.factor(countryName))

Alternatively, look at the fastdummies package.

This topic was automatically closed 21 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.