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-...
I was stuck on a hw question with this for 6 hours and you were my breakthrough. TYSM
Hi Michelle, it is great to hear that my video helped you.
Thank you for this video. I was stuck on a assignment question and your video helped me to solve it. Thank again.
I am glad to hear this! You are welcome!
Thank you for this video! I was needing a way to dummy code for a level categorical variable and this did the trick!
Thank you for sharing this with me!
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!
Thank you! I try to add videos whenever I find the time
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!
Thanks for letting me know! I am so happy to hear that!
Thanks a lot! I have been stuck on that question.
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!
Glad it was helpful!
Thank you so much! Quickly solved my problem here with the help from you video!
Great to hear this!
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
姐妹,你真的很棒!!以你为榜样!!
谢谢
Thank you Yan!
i damn love your work and explanation, thank you very much!!!!!!!! :)
I am glad to hear you find some videos you love:)
Thank you, exactly what I was looking for!!
Thank you so much. You totally saved the day >.
I am so glad to hear that! Thanks for sharing with me!
Perfect! Thank you!
I am new to R, this function so great !
Yes. R has many wonderful packages and functions
@@datasciencewithyan4124 btw, I think you need speak out louder or adjust your mic. Your sound is too small.
Thanks! I used a microphone for my recent videos. Hope it helps
It was so helpful....Thank you!
You are welcome
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?
Great. Thank you
Thanks for learning with me
thanku...
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 :(
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.
Dummy variables are not showing using fixed effect, R drops the variables because of multicollinearity...I don't know what to do now
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.
Very useful but didn't get results that I used for three categories
What’s the error message?
Thank you so much!
You are welcome! Thanks for checking on my video
Very impressive and helpful thanks
Thanks!
@@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
Sorry I may not be able to help on this specific problem
@@datasciencewithyan4124 not an issue, thanks for reply
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"
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
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
R is very strict about lower case and upper case letters! Yes, View can only be used like View
I have a test on this stuff today
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.
do you mean change the labels?
it's not working for me, can u please help-!!!
Can you share some details?
THIS ISN'T HELOING ME
sorry to hear that. What is the question you are trying to solve?