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

Поділитися
Вставка
  • Опубліковано 6 січ 2025

КОМЕНТАРІ • 58

  • @michelleguo7068
    @michelleguo7068 3 роки тому +13

    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!

  • @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

  • @michaelroyer7150
    @michaelroyer7150 3 роки тому

    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!

  • @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!

  • @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 2 роки тому +1

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

  • @user-kg4kk1dg8p
    @user-kg4kk1dg8p 11 місяців тому +1

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

  • @유양학생보건학과
    @유양학생보건학과 2 роки тому

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

  • @drewfasa
    @drewfasa 2 роки тому

    Thank you, exactly what I was looking for!!

  • @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?

  • @yaarithanan1994
    @yaarithanan1994 Рік тому

    Perfect! Thank you!

  • @AndreSantos-lm1do
    @AndreSantos-lm1do 2 роки тому +1

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

  • @airam2968
    @airam2968 Рік тому +1

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

  • @SC-bi6my
    @SC-bi6my 3 роки тому

    I am new to R, this function so great !

    • @datasciencewithyan4124
      @datasciencewithyan4124  3 роки тому

      Yes. R has many wonderful packages and functions

    • @SC-bi6my
      @SC-bi6my 3 роки тому

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

    • @datasciencewithyan4124
      @datasciencewithyan4124  3 роки тому

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

  • @dka9756
    @dka9756 10 місяців тому

    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  10 місяців тому

      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.

  • @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.

  • @vahidemajidifar6278
    @vahidemajidifar6278 2 роки тому

    It was so helpful....Thank you!

  • @eyadha1
    @eyadha1 2 роки тому

    Great. Thank you

  • @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

  • @saimasideeq7254
    @saimasideeq7254 2 роки тому

    thanku...

  • @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: ua-cam.com/video/UKkAZyk8zj4/v-deo.html

  • @jinalpatel477
    @jinalpatel477 3 роки тому +1

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

  • @nicolasrojas2044
    @nicolasrojas2044 3 роки тому

    Thank you so much!

  • @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-!!!

  • @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

  • @petercross1879
    @petercross1879 2 роки тому

    THIS ISN'T HELOING ME