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.

Комментарии • 104

  • @RProgramming101
    @RProgramming101  Год назад +1

    Get my FREE cheat sheets for R programming and statistics (including transcripts of these lessons) here: www.learnmore365.com/courses/rprogramming-resource-library

  • @nikolanedic500
    @nikolanedic500 2 года назад +8

    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

  • @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 5 месяцев назад +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 4 месяца назад +1

      I encounter same error

    • @robertodimolfetta5505
      @robertodimolfetta5505 4 месяца назад +1

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

    • @panwall1327
      @panwall1327 4 месяца назад +1

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

    • @cueyyyy
      @cueyyyy 3 месяца назад +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!

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

  • @negusuworku2375
    @negusuworku2375 2 месяца назад

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

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

  • @haraldurkarlsson1147
    @haraldurkarlsson1147 3 года назад

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

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

  • @yosolonopuedo
    @yosolonopuedo 4 года назад +2

    Clear and to the point. Great video!

  • @Easykzz
    @Easykzz 11 месяцев назад

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

  • @konstantinosmaravegias4198
    @konstantinosmaravegias4198 3 года назад

    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.

  • @mightyowl1668
    @mightyowl1668 4 года назад +1

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

  • @boristolkachev9470
    @boristolkachev9470 4 года назад +2

    Excellent as always! Thanks very much indeed

  • @panwall1327
    @panwall1327 4 месяца назад +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".

  • @vanishreehegde5629
    @vanishreehegde5629 4 года назад +1

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

  • @CindyLaquidara
    @CindyLaquidara Год назад

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

  • @shadrackrotino7469
    @shadrackrotino7469 8 месяцев назад

    Making R fun. Thumbs up.

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

  • @Shawn-gm4cf
    @Shawn-gm4cf 3 года назад

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

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

  • @muhammedhadedy4570
    @muhammedhadedy4570 2 года назад +2

    Sir, you are a legend.

  • @MCshaneization
    @MCshaneization 2 года назад +1

    This guy is next-level

  • @LuffyFA
    @LuffyFA 4 года назад

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

  • @woelneberg
    @woelneberg 3 года назад

    Thank you for these great tutorials!

  • @romanvasiura6705
    @romanvasiura6705 Год назад

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

  • @kingdeification
    @kingdeification 3 года назад

    Awesome video!! 👍

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

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

  • @heartheart5543
    @heartheart5543 3 года назад +1

    thank you so much, very clear

  • @vinodsammangi2876
    @vinodsammangi2876 3 года назад

    Excellent Mam

  • @poojamahesh8594
    @poojamahesh8594 3 года назад

    Really a Great video!!!!

  • @setarehsohail5422
    @setarehsohail5422 2 года назад +1

    perfect!

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

  • @user-pu9ll7vd5m
    @user-pu9ll7vd5m 4 месяца назад

    Thank you -

  • @tomaszlipinski1870
    @tomaszlipinski1870 4 года назад +1

    Thank you sir :)

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

  • @th2315
    @th2315 2 года назад +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.

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

  • @simransingh2778
    @simransingh2778 4 года назад

    You are R wizard

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

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

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

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

  • @user-zc6bv8ej9g
    @user-zc6bv8ej9g 3 года назад +1

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

  • @htoomyataung3002
    @htoomyataung3002 4 месяца назад

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

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

  • @gurkirtansingh1771
    @gurkirtansingh1771 11 месяцев назад

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

  • @ameenabdulbarr8342
    @ameenabdulbarr8342 Год назад +1

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

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

  • @nisamoin1165
    @nisamoin1165 Год назад

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

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

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

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

  • @user-fg6hh6jg4k
    @user-fg6hh6jg4k Год назад

    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!

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

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

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

  • @umarhussain5957
    @umarhussain5957 2 года назад

    Respected sir please also share your scripts

  • @medicalmarvels976
    @medicalmarvels976 8 месяцев назад

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

  • @Senapsdesign
    @Senapsdesign 2 месяца назад

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

  • @cooltube2000
    @cooltube2000 2 года назад

    bing bada boom shakala

  • @shivangideshwal4208
    @shivangideshwal4208 4 года назад +1

    Could you be a little louder?

  • @TheGreygoose87
    @TheGreygoose87 Год назад

    R went woke. 🙄