use ifelse() function in R to create dummy variables and categorical variables

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • In this video, you are going to learn:
    1. how to create a dummy variable from a numerical variable
    2. how to create a categorical variable with 2 or 3 categories from a numerical variable.
    I just made a new video here to create dummy variables all at once: • creating dummy variabl...
    The R code for this video can be found here: github.com/yz-...
    You may find the playlist on R for data science book club here ( I have been recording the videos according to a popular book): • R for data science boo...
    You may set the video speed to 1.25 or 1.5 to make the video go faster by clicking the setting from the bottom right of the video, and set the speed to 1.25 or 1.5.
    You need to install R and RStudio before you use RStudio. Follow this instruction here:
    github.com/yz-...

Комментарии • 59

  • @michelleguo7068
    @michelleguo7068 3 года назад +12

    I was stuck on a hw question with this for 6 hours and you were my breakthrough. TYSM

  • @mprawesh
    @mprawesh 2 года назад +1

    Thank you for this video. I was stuck on a assignment question and your video helped me to solve it. Thank again.

  • @ericandrade6872
    @ericandrade6872 2 года назад +2

    Thank you for this video! I was needing a way to dummy code for a level categorical variable and this did the trick!

  • @whynotfandy
    @whynotfandy 2 года назад

    I'm very happy to have stumbled across your YT channel. I subscribed after I checked and saw that you continue to create content. I try to learn something new every day. I'll catch up on your previous videos and hope to see more!

  • @michaelroyer7150
    @michaelroyer7150 2 года назад

    I cannot thank you enough for this understandable example and description. I had been stuck trying to conditionally recode multiple variables in my dataset for days. This was the help I needed. Thank you thank you thank you!

  • @user-kg4kk1dg8p
    @user-kg4kk1dg8p 7 месяцев назад +1

    Thanks a lot! I have been stuck on that question.

  • @airam2968
    @airam2968 Год назад

    this is so helpful!!!! I thank God you exist! This is the video number 25 I've seen today and finally yours explained everything I needed!! Thanks a lot!

  • @Pooh991
    @Pooh991 Год назад +1

    Thank you so much! Quickly solved my problem here with the help from you video!

  • @Sruthia-p8s
    @Sruthia-p8s Год назад

    Thank you!
    I was searching for the code to run this:
    Gn) In the existing R database - iris, there exists outliers in the column values of Sepal.Width.
    Ques.) To create a new column that signify that the record is an outlier ('Yes' for outlier and 'No' for other records).
    Ans) Built through this video:
    summary(iris$Sepal.Width)
    #Get quartile values from the summary
    q1=2.8
    q3=3.3
    InterQuartileRange=IQR(iris$Sepal.Width)
    LowerWhisker=q1-(1.5*InterQuartileRange)
    UpperWhisker=q3+(1.5*iInterQuartileRange)
    iris$is_Outlier=ifelse(iris$Sepal.Width>UpperWhisker | iris$Sepal.Width

  • @user-sh5os8pd2o
    @user-sh5os8pd2o 2 года назад

    姐妹,你真的很棒!!以你为榜样!!

  • @fred4859
    @fred4859 Год назад +1

    Thank you Yan!

  • @airam2968
    @airam2968 Год назад +1

    i damn love your work and explanation, thank you very much!!!!!!!! :)

  • @drewfasa
    @drewfasa Год назад

    Thank you, exactly what I was looking for!!

  • @AndreSantos-lm1do
    @AndreSantos-lm1do 2 года назад +1

    Thank you so much. You totally saved the day >.

  • @yaarithanan1994
    @yaarithanan1994 Год назад

    Perfect! Thank you!

  • @SC-bi6my
    @SC-bi6my 2 года назад

    I am new to R, this function so great !

    • @datasciencewithyan4124
      @datasciencewithyan4124  2 года назад

      Yes. R has many wonderful packages and functions

    • @SC-bi6my
      @SC-bi6my 2 года назад

      @@datasciencewithyan4124 btw, I think you need speak out louder or adjust your mic. Your sound is too small.

    • @datasciencewithyan4124
      @datasciencewithyan4124  2 года назад

      Thanks! I used a microphone for my recent videos. Hope it helps

  • @vahidemajidifar6278
    @vahidemajidifar6278 2 года назад

    It was so helpful....Thank you!

  • @thulfiqaral-graiti7131
    @thulfiqaral-graiti7131 2 года назад

    How can I change 5 sampling dates (under season factor , character) to make them work in regression model? I change season to a factor using as.factor option, but did not work and showed NA in output result for this factor?

  • @eyadha1
    @eyadha1 Год назад

    Great. Thank you

  • @saimasideeq7254
    @saimasideeq7254 2 года назад

    thanku...

  • @kodamaz
    @kodamaz Год назад

    Hi! Do you know how to create a new categorical variable from an old categorical variable? I have a character variable (column) called “country” with 38 different country types (or categories) (e.g., US, IN, etc), & I need to create a new variable condensing it to just 3 categories. I’ve searched online for hours but every example I find only shows how to create numeric variables. I have tried if-else-return, ifelse, & case_when with no success :(

    • @datasciencewithyan4124
      @datasciencewithyan4124  Год назад

      One thing you can do is to prepare a dataset in excel file with two columns, one column is the countries, another column are their new categories. Import this data into R. And merge this dataset with you originally imported R dataset.

  • @dka9756
    @dka9756 6 месяцев назад

    Dummy variables are not showing using fixed effect, R drops the variables because of multicollinearity...I don't know what to do now

    • @datasciencewithyan4124
      @datasciencewithyan4124  6 месяцев назад

      It is possible that one variable tells all the information about the other variable. You may consider removing the variable you don’t want to include.

  • @jinalpatel477
    @jinalpatel477 3 года назад +1

    Very useful but didn't get results that I used for three categories

  • @nicolasrojas2044
    @nicolasrojas2044 2 года назад

    Thank you so much!

  • @ltbhupinder1811
    @ltbhupinder1811 3 года назад

    Very impressive and helpful thanks

    • @datasciencewithyan4124
      @datasciencewithyan4124  3 года назад

      Thanks!

    • @ltbhupinder1811
      @ltbhupinder1811 3 года назад

      @@datasciencewithyan4124 hi, I am having text data like name country in which studies held and I am willing to conduct moderator analysis to see the effects of culture on my variable. Now question arises, how to use this text data in moderator analysis. Actually I am doing meta analysis of studies relating in the field of Leadership styles and their impact on organizational performance. Can you help me in this regards

    • @datasciencewithyan4124
      @datasciencewithyan4124  3 года назад

      Sorry I may not be able to help on this specific problem

    • @ltbhupinder1811
      @ltbhupinder1811 3 года назад

      @@datasciencewithyan4124 not an issue, thanks for reply

  • @thulfiqaralijasimal-graiti5077
    @thulfiqaralijasimal-graiti5077 2 года назад

    Hi, I have five sampling dates under one column named as season (character variable), when I did {iflese function} to create the dummy variable for these 5 dates ( having one as a baseline-no function for it), using the following script: datafilename$"date1"

    • @datasciencewithyan4124
      @datasciencewithyan4124  2 года назад

      Hi Thulfiqar, I just created a video on creating dummy variables all at once. It is quicker and easier than using ifelse function. The link is here: ruclips.net/video/UKkAZyk8zj4/видео.html

  • @SidHawklord
    @SidHawklord 2 года назад

    Don't you find it ironic that View() only works with a capital V? My understanding of R was that EVERYTHING should always be lower case

    • @datasciencewithyan4124
      @datasciencewithyan4124  2 года назад

      R is very strict about lower case and upper case letters! Yes, View can only be used like View

  • @petercross1879
    @petercross1879 2 года назад

    I have a test on this stuff today

  • @tebogomokumako2571
    @tebogomokumako2571 2 года назад

    Yan please kindly assist with creating already categorised variables. e.g if i have income data captured as 1. below $10 ; 2. $10-$20 3. $20-$50; 4 Above $50.

  • @alizakhan7791
    @alizakhan7791 2 года назад

    it's not working for me, can u please help-!!!

  • @petercross1879
    @petercross1879 2 года назад

    THIS ISN'T HELOING ME