samedi 18 septembre 2021

How to use IfElse function with character variables in R

I need help, since I am trying to create dummy variables with R and my code is not working. I would like to change the auction location to 1 if it is Hong Kong and to 0 if it is not. By applying the code below all the values become 1 and not only the one corresponding to Hong-Kong.

Here is the code I applied:

Database$HGK=ifelse(Database$Auction_location>="Hong-Kong",1,0)

Can you help me to find the solution?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire