Recoding data using R programming. Using the tidyverse and dplyr packages to create a new variable

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

ความคิดเห็น • 104

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

    Get my FREE cheat sheets for R programming and statistics (including transcripts of these lessons) here: www.learnmore365.com/pages/membership-r-programming-data-visualization-and-research-methods

  • @nikolanedic500
    @nikolanedic500 2 ปีที่แล้ว +9

    Hands down the best channel on R programming.

    • @RProgramming101
      @RProgramming101  2 ปีที่แล้ว +2

      So nice of you - thanks for the great feedback Nikola!!

  • @rameshgajbhiye6745
    @rameshgajbhiye6745 3 ปีที่แล้ว +24

    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

  • @matosleni
    @matosleni 3 ปีที่แล้ว +4

    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".

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

      there is a "sex" column that contains the values in this dataset. It got me too when I was doing this tutorial.

  • @jd5481
    @jd5481 2 ปีที่แล้ว +2

    This guy is great... explains everything better than my uni program. Keep them coming!

  • @nursahidassafaat6283
    @nursahidassafaat6283 4 ปีที่แล้ว +8

    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

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

    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!

  • @hannahplantana
    @hannahplantana 2 ปีที่แล้ว +2

    Your videos are extremely helpful and concise!! Thanks you for sharing

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

      Glad it helped, thank you! Most welcome!

  • @konstantinosmaravegias4198
    @konstantinosmaravegias4198 4 ปีที่แล้ว

    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.

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

    Short but to the point - excellent. I always learning something new from these videos. Keep them comming...

  • @balatangiisuran5403
    @balatangiisuran5403 4 ปีที่แล้ว +4

    Very useful as usual. I want to let you know that I am learning R through your videos. Very excited to see more videos.

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

    learning R, step by step by your videos. Plz keep doing what you do🤩

  • @negusuworku2375
    @negusuworku2375 4 หลายเดือนก่อน

    Bro what ?! I am learning a lot. Thank you. Keep it up. Bless you.

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

    So easy explanations. Makes it easy to learn. Thank you.

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

    This is so incredibly clear. Thank you very much and it’s fun too

  • @yosolonopuedo
    @yosolonopuedo 4 ปีที่แล้ว +2

    Clear and to the point. Great video!

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

    Immediately subscribed! Please keep those videos coming!! Amazing tutorials!

  • @boristolkachev9470
    @boristolkachev9470 4 ปีที่แล้ว +2

    Excellent as always! Thanks very much indeed

  • @Crystalspencer93
    @Crystalspencer93 2 ปีที่แล้ว +24

    ## 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!!”

    • @lancemisland3126
      @lancemisland3126 6 หลายเดือนก่อน +1

      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".

    • @truth4375
      @truth4375 6 หลายเดือนก่อน +1

      I encounter same error

    • @robertodimolfetta5505
      @robertodimolfetta5505 6 หลายเดือนก่อน +1

      Thank you. I would've lost an hour to understand why it didn't work.

    • @panwall1327
      @panwall1327 5 หลายเดือนก่อน +1

      this is a great learning exercise about code, too. specifics matter when writing code.

    • @cueyyyy
      @cueyyyy 5 หลายเดือนก่อน +1

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

  • @Shawn-gm4cf
    @Shawn-gm4cf 3 ปีที่แล้ว

    Your videos are excellent. I've learned so much already.

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

    This guy is next-level

  • @muhammedhadedy4570
    @muhammedhadedy4570 2 ปีที่แล้ว +2

    Sir, you are a legend.

  • @swatighoshsinha
    @swatighoshsinha 4 ปีที่แล้ว +3

    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?

  • @LuffyFA
    @LuffyFA 4 ปีที่แล้ว

    Incredible and very useful video, thank you for your work and dedication!

  • @Padmaprana
    @Padmaprana 4 ปีที่แล้ว

    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!

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

    Thank you for these great tutorials!

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

    thank you so much, very clear

  • @rpg6570
    @rpg6570 3 ปีที่แล้ว +2

    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

  • @2008MiniMonty
    @2008MiniMonty 3 ปีที่แล้ว

    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

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

    Thank you for these videos)
    Also I like your additional words such as "boomshakalaka" 😄)

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

      Thank you! 😃 Glad you liked it!

  • @shadrackrotino7469
    @shadrackrotino7469 10 หลายเดือนก่อน

    Making R fun. Thumbs up.

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

    Awesome video!! 👍

  • @panwall1327
    @panwall1327 5 หลายเดือนก่อน +1

    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".

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

    Really a Great video!!!!

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

    what do you mean by the function na.omit()

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

    Thank you sir :)

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

    perfect!

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

    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.

  • @space5more
    @space5more 6 หลายเดือนก่อน

    Thank you -

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

    Excellent Mam

  • @emansatti7694
    @emansatti7694 4 ปีที่แล้ว

    Is there a video on how to run the statistical tests on R in this incredible channel 👌?

    • @RProgramming101
      @RProgramming101  4 ปีที่แล้ว +2

      Hi there. I’ll be creating some videos on doing stats tests very soon. Thanks for the comment.

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

    What keys do you press to execute the query and view its results? Windows user.
    Thank you😊

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

    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!

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

      omg thank you so much, I was wondering for such a long time why the date wasn't available anymore after running the code

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

    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

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

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

  • @htoomyataung3002
    @htoomyataung3002 5 หลายเดือนก่อน

    Am I doing wrong? After run filter( gender == "male" | gender == "female"), the table showed no data available instead of converting to male/female.

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

    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?

  • @simransingh2778
    @simransingh2778 4 ปีที่แล้ว

    You are R wizard

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

    Is there any shortcut for %in%? Like ctrl + shift + m for %>%...

    • @RProgramming101
      @RProgramming101  4 ปีที่แล้ว +2

      I don't think so (if you find one, do let me know)

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

    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?

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

      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.

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

    How to recoding variable in name coloumn, if there are over a thousand names. I want to change the name to serial number

  • @YShao-k9v
    @YShao-k9v ปีที่แล้ว

    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!

  • @4141-i7o
    @4141-i7o 4 ปีที่แล้ว +1

    How to recode if there were more than 3 categories?? Cuz there are only True and False.

  • @onyonable
    @onyonable 4 ปีที่แล้ว +2

    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

    • @RProgramming101
      @RProgramming101  4 ปีที่แล้ว +9

      Haha. Am back and will upload a lot over the next few months. 👍🏻👍🏻👍🏻

    • @nursahidassafaat6283
      @nursahidassafaat6283 4 ปีที่แล้ว

      Me too! and i'm so glad that Dr. Greg Martin is back!

    • @onyonable
      @onyonable 4 ปีที่แล้ว

      @@RProgramming101 glad to hear that, apart from the clarity of your explanation, your production value is top notch

    • @ramthakur7981
      @ramthakur7981 4 ปีที่แล้ว

      @@RProgramming101 I heard the greg martin passed away. The person who is speaking in this video. is that true

    • @ramthakur7981
      @ramthakur7981 4 ปีที่แล้ว

      Is this the guy in this video
      www.corkbeo.ie/news/local-news/tributes-cork-dad-greg-martin-16880970

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

    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

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

      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?

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

    wait do we need to create the sw file first? and copy paste the wanted data from the starwars file through excel?

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

      I'm confused because I was hoping to have a new datafile formed with new columns , using the data from the starwars file

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

      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

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

    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"))

  • @jacobhershenhouse6633
    @jacobhershenhouse6633 4 ปีที่แล้ว

    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

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

      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

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

    Respected sir please also share your scripts

  • @medicalmarvels976
    @medicalmarvels976 10 หลายเดือนก่อน

    filter(gender %in% c("male", "Female")) it is not working for me

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

    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.

  • @Senapsdesign
    @Senapsdesign 4 หลายเดือนก่อน

    but the data says "sex" female/male and "gendeer" masculine/femenine".

  • @edgarl.calvadoresii9479
    @edgarl.calvadoresii9479 2 ปีที่แล้ว

    Why is it my data frame got 0 observations when I fIltered out the gender into male and female?

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

      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")

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

    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.

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

    Heisenberg: i am the cook....book of R

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

    Could you be a little louder?

    • @RProgramming101
      @RProgramming101  4 ปีที่แล้ว

      Will do.. 😁 thanks for the feedback.

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

    bing bada boom shakala

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

    R went woke. 🙄