Recoding data using R programming. Using the tidyverse and dplyr packages to create a new variable
HTML-код
- Опубликовано: 21 авг 2024
- This video is about how to recode data and manipulate data using R programming. It is really an R programming for beginners videos. It provides a demonstration of how to recode data using the tidyverse package (specifically the dplyr package in the tidyverse set of packages). The demonstration is in R Studio. This channel is for people who are interested in quantitative and statistical analysis using R. Everything to do with data science. This video is part of the "cleaning data" series.
Get my FREE cheat sheets for R programming and statistics (including transcripts of these lessons) here: www.learnmore365.com/courses/rprogramming-resource-library
Hands down the best channel on R programming.
So nice of you - thanks for the great feedback Nikola!!
This guy is so invested in his audience, did someone notice?! he is using new words in every video like voila, Bing Bada boom, etc to keep the audience engaged...great efforts n quality of content is immaculate
## ATTENTION NEW CODERS ##
Re: updated dataset in tidyverse
Thank you to the older comments on this video to let me know that the elements of the “gender” variable are masculine and feminine whereas the male and female elements belong to the “sex” variable. I also was coding along and lost my “View(sw)” data as soon as I typed along (code line 9) with the video as well. Therefore, by replacing male and female with masculine and feminine respectively, code example:
filter(gender %in% c(“masculine”, “feminine”))
I got my data back in the View(sw) pane!
\(^o^)/ “boom-shack-a-lacka!!”
I think that we should be using the "sex" column to follow with our lovely teacher in the video. He speaks about "male "and "female", instead of masculine and feminine. I think that the column names was changed. the code :
na.omit() %>%
mutate(height = height/100) %>%
filter(sex == "male" |
sex == "female")
tells R to remove all NA, then mutate height from cm to m, then to filter sex (or gender in the video's case) according to male and female. In the "masculine", "feminine" case we didn't have to continue with the filter() code as there's only "masculine" and "feminine" in that gender column. The "sex" column has the further need for the filter() code as it still includes other sexes including "hermaphroditic" and "none".
So I think that the new code would follow along the lines of:
sw %
select(name, height, mass, sex) %>%
rename(weight = mass) %>%
na.omit() %>%
mutate(height = height/100) %>% # changing height from cm to m
filter(sex %in% c("male", "female"))
Substituting "gender" as in the video for "sex".
I encounter same error
Thank you. I would've lost an hour to understand why it didn't work.
this is a great learning exercise about code, too. specifics matter when writing code.
@@lancemisland3126 thank you so much! i tried practicing filtering on my own and couldn't understand solutions elsewhere until watching this video and finding your comment!
Thanks again for all excellent tutorials!
Quick Note: someone has changed the gender options from the original data set (starwars). Nowadays, they are called either "masculine" or "feminine".
there is a "sex" column that contains the values in this dataset. It got me too when I was doing this tutorial.
This guy is great... explains everything better than my uni program. Keep them coming!
Will do :)
I love the way you explained that, quiet simple, clear, and saving time!
I would be very happy if you could make a video tutorial on how to make real-time questionnaires and automatically process them, and give feedback to respondents regarding their scores and their position in the global norms :D
Bro what ?! I am learning a lot. Thank you. Keep it up. Bless you.
Very useful as usual. I want to let you know that I am learning R through your videos. Very excited to see more videos.
Short but to the point - excellent. I always learning something new from these videos. Keep them comming...
Thanks, will do!
Thank you for these videos - they are great!! I have been teaching myself R and your videos are super helpful! Please keep making more. Packages are poetry!
Your videos are extremely helpful and concise!! Thanks you for sharing
Glad it helped, thank you! Most welcome!
Clear and to the point. Great video!
learning R, step by step by your videos. Plz keep doing what you do🤩
Thank you. This is pure gold, i just wanted to figured out how the recode( ) works, but you made me to understand deeper how other functions works too.
Thank you, for the fast and simple example.
Immediately subscribed! Please keep those videos coming!! Amazing tutorials!
Excellent as always! Thanks very much indeed
You are most welcome.
If you are watching this in 2024, and you get stuck at 3:30, the Star Wars data set has changed "male" to "masculine" and "female" to "feminine".
So easy explanations. Makes it easy to learn. Thank you.
This is so incredibly clear. Thank you very much and it’s fun too
Making R fun. Thumbs up.
Thank you so much for posting! I've been trying to teach myself recently. Every single one of your videos have been coming at a perfect time and are exactly everything I've been needing and wanting to learn. So directly relevant. Can't wait to see more!
Your videos are excellent. I've learned so much already.
Great video thanks - I believe the starwars dataset has been updated to replace "gender" with "sex". I hope that helps people who are coding alone with the video
Sir, you are a legend.
Wow, thanks
This guy is next-level
Thank you for the kind words :)
Incredible and very useful video, thank you for your work and dedication!
Thank you for these great tutorials!
Thank you for these videos)
Also I like your additional words such as "boomshakalaka" 😄)
Thank you! 😃 Glad you liked it!
Awesome video!! 👍
for those getting a null value after doing the gender check your star wars data the gender labels may have changed to masculine and feminine
Hi quick question, what should I do after getting the null variable, even if i delete the code, my dataset in the environment has 0 observations. Do I have to run the whole thing again or is there an easier way to do this?
Hi, thanks for the simple explanation. Is there a way to categorize into 3 categories big, medium and small based on the combination of height and weight variables?
thank you so much, very clear
Excellent Mam
Really a Great video!!!!
perfect!
Thanks!!
Great video - thank you very much, this may have already been asked but just wondering is there anywhere you upload the code you have used in this video? Would be very useful, thanks
Thank you -
Thank you sir :)
This is from the future: there is an update in the dataset. Instead of using male and female, now the dataset uses masculine and feminine.
sir, how do I use mutate() to obtain a categorical variable with more than 2 levels, let's say if there is a "medium" in size.
Have they changed the starwars dataset since this video? My gender variable only has “feminine” and “masculine” as levels. So the filters in your video (“male”, “female”) return an empty dataframe. Of course you can quite easily figure out why if you check the original df, but it might be a bit confusing if you are totally new to this.
Otherwise great vids!
omg thank you so much, I was wondering for such a long time why the date wasn't available anymore after running the code
You are R wizard
No need to create a logical vector before yu assign big and small; just do: mutate(size = if_else(height > 1.0 & weight > 75, "big", "small"))
Is there a video on how to run the statistical tests on R in this incredible channel 👌?
Hi there. I’ll be creating some videos on doing stats tests very soon. Thanks for the comment.
Are u start uploading again? Man, in the span of the past 2 months I've been watching all ur data science videos knowing that the channel dead
Haha. Am back and will upload a lot over the next few months. 👍🏻👍🏻👍🏻
Me too! and i'm so glad that Dr. Greg Martin is back!
@@RProgramming101 glad to hear that, apart from the clarity of your explanation, your production value is top notch
@@RProgramming101 I heard the greg martin passed away. The person who is speaking in this video. is that true
Is this the guy in this video
www.corkbeo.ie/news/local-news/tributes-cork-dad-greg-martin-16880970
Love your teaching and your work am very grateful it has helped a lot but please next time tell us to set
library(tidyverse)
conflict_prefer(
dplyr:: filter(),
dplyr::lag(),
)
sw %
Felt like pulling teeth, because my filter function refused to work and my output refused to print. when we got to the filter section. dplyr was being masked by r base
How to recode if there were more than 3 categories?? Cuz there are only True and False.
Am I doing wrong? After run filter( gender == "male" | gender == "female"), the table showed no data available instead of converting to male/female.
Is there any shortcut for %in%? Like ctrl + shift + m for %>%...
I don't think so (if you find one, do let me know)
Heisenberg: i am the cook....book of R
what do you mean by the function na.omit()
Ggplott is plotting against me.hours,weeks and months go by trying to write one single block of code, thanks for trying to help,Gregg.
You can do it!
What keys do you press to execute the query and view its results? Windows user.
Thank you😊
Kindly clarify my query... I have a data set containing 47body parts, I have to recode it to 1,2,3,4,...kindly explain me the line of code for it..
How can I reduce question scales of a survey question? for example, the question has 10 options (1-10), but I want to reduce to 3 options (0 = 1 2 3) (1 = 4 5 6 7) (2 = 8 9 10). Could you please help or indicate any video?
I never saw you create sw. When I ran sw % it did not create a new dataset sw. The dataset sw already existed. What did I miss?
sw % is not a lone line of code. In the tidyverse, the pipe (%>%) indicates that we are continuing onto the next line with more information. Every time he hits command enter, he is running the entire chunk of code that is on the screen, recreating sw each time with the new parameters.
Hi, does anyone know why my code worked, but no new variable appeared in my dataset? I used mutate, and the code worked, no errors was reported. I would appreciate your help!
when trying to load the tidyverse library I get the following error:
> library(tidyverse)
Error: package or namespace load failed for ‘tidyverse’ in namespaceExport(ns, exports):
undefined exports: %>%
do you know a way around this? my code matches yours
have you installed the tidyverse package already? if not, do so by typing
install.packages("tidyverse)
after the package has installed run
library(tidyverse) or require(tidyverse)
hope this helps
How to recoding variable in name coloumn, if there are over a thousand names. I want to change the name to serial number
wait do we need to create the sw file first? and copy paste the wanted data from the starwars file through excel?
I'm confused because I was hoping to have a new datafile formed with new columns , using the data from the starwars file
Thankfully we can do it all from right within R! starwars exists within R as a dataframe, so it is often used for teaching. We read the code sw
Respected sir please also share your scripts
filter(gender %in% c("male", "Female")) it is not working for me
but the data says "sex" female/male and "gendeer" masculine/femenine".
Why is it my data frame got 0 observations when I fIltered out the gender into male and female?
It's possible that you forgot the quotations, leading R to fail to find any matches, or the fact that the gender variable actually has values "masculine" and feminine" in it these days. There is another variable in the dataframe called sex that contains values of male and female. This should work: filter(sex == "male" |
sex == "female")
bing bada boom shakala
haha - always boom shakalaka
Could you be a little louder?
Will do.. 😁 thanks for the feedback.
R went woke. 🙄