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

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 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.

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

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

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

  • @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 10 หลายเดือนก่อน +1

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

  • @유양학생보건학과
    @유양학생보건학과 2 ปีที่แล้ว

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

  • @drewfasa
    @drewfasa 2 ปีที่แล้ว

    Thank you, exactly what I was looking for!!

  • @yaarithanan1994
    @yaarithanan1994 ปีที่แล้ว

    Perfect! Thank you!

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

  • @airam2968
    @airam2968 ปีที่แล้ว +1

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

  • @AndreSantos-lm1do
    @AndreSantos-lm1do 2 ปีที่แล้ว +1

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

  • @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 2 ปีที่แล้ว

    Great. Thank you

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

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

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

  • @nicolasrojas2044
    @nicolasrojas2044 3 ปีที่แล้ว

    Thank you so much!

  • @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: th-cam.com/video/UKkAZyk8zj4/w-d-xo.html

  • @saimasideeq7254
    @saimasideeq7254 2 ปีที่แล้ว

    thanku...

  • @jinalpatel477
    @jinalpatel477 3 ปีที่แล้ว +1

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

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

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

  • @alizakhan7791
    @alizakhan7791 2 ปีที่แล้ว

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

  • @petercross1879
    @petercross1879 2 ปีที่แล้ว

    THIS ISN'T HELOING ME

    • @datasciencewithyan4124
      @datasciencewithyan4124  2 ปีที่แล้ว

      sorry to hear that. What is the question you are trying to solve?