Hello in this lecture you are going to learn how to recode the categorical variables all the factors
in our we need to recode our variable when they are coded in a way that is not convenient for us for
the analyst.
For the soundpost I will use the same data frame deam all that contain information about a group of
owners.
I'm going to code the variable gender of Paulo's the old value male will take the new value won and
they all value female will take the new value too and I will create a new variable gender too.
In the process first I will use the brackets so that they are how to do it.
So we tell the program that we want a new variable gender to indicate operator dream on and the new
variable gender 2 will take the following values.
If we all of the variable gender is made the new value of the variable gender 2 is won and if the order
variable gender is female as the value of the new variable gender 2 will be 2.
You'll notice that I put 1 and 2 within quotation marks because our new Garibaldian under 2 will be
a factor too.
So that creates the new variable gender too.
And then you get the new view again.
Our data Pramer demon control and her Quraan of this other Conneaut is the variable gender to what added
at the end and it take the value won when the gender is made and the value to.
When the gender is female as we request it
we can do the same type of recording used in the plier package.
The function revalue.
First of all we have to load the player back which will require
and now in the day to a great deal more work to create a new variable agenda really you the Ponson revalue
how this function looks like.
First of all we must specify the old variable gender and then we must specify how we want to do the
recording using the C function.
So in the past that of the function we must specify the parent all value new value so that they all
the value mail will be converted into the new value wan and they all value remain will be converted
into the new value to the new value will be stored in the vavle gender theory that we will create with
that try that
and you the variable the data frame D-Mont. again.
You can notice here at the and the variable gender 3.
That of course take the value won when the gender is male and the value to where the gender is females.
So that's how to use the real value function.
Very important in the variable to code is not a factor you must convert it into a factor before recoding
you using that factor function.
So you create a new variable which is the gender which is a factor of gender.
And it is not necessary but as I said if the initial variable is not a factor you must recode that you
must convert the story into x factor of course.
You can recode into the same variable without creating a new one for this.
You just use the same variable name in both side of the Evaluate function.
So as you notice here we have the new variable Deewar gender.
OK.
Which is obtained by converting the variables the same variable gender and the pairs all the new value
are as follows.
Made equal to 1 though made it converted into one and we made it convert it into two.
OK.
Don't forget to use the concatenate function here.
I'll try that control and or and control and so that the other variable gender again.
The categories are not male and female anymore but one and two requested one corresponding to the male
object and two corresponding to the females.
Objects
that are recording the categorical variables.
Thank you.