How to calculate column mean & mean for sub-groups in R or RStudio

Поделиться
HTML-код
  • Опубликовано: 27 авг 2022
  • This video shows you how to calculate mean for a category inside a given numeric variable. For example, calculating the mean age of women, calculating the mean age of individuals are men and were born in 2000, calculating the mean age of individuals who are women or who were born in 2000, etc.
    How to calculate mean for a row or a selection of rows in R:
    • How to calculate row m...
    How to omit subjects with missing data, remove or ignore NA in calculations in R studio:
    • How to omit subjects w...
    How to replace data values, including missing NAs data values in R or RStudio:
    • How to replace data va...
    Please subscribe to my channel:
    / minukuututorials

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

  • @karinabik5747
    @karinabik5747 Год назад +2

    You are amazing

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

    Aye man, real helpful bro 🙏🏽

  • @nannaporshia2836
    @nannaporshia2836 Год назад +2

    WOW! Thank you so so much, greetings from Norway! 😊

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

      You’re most welcome! Would love to visit or even relocate to Norway 🇳🇴
      I am currently in Paris :)

    • @nannaporshia2836
      @nannaporshia2836 10 месяцев назад

      @@MinukuuTutorials Experiencing different cultures are always great. ☺️

  • @dem0nicrush
    @dem0nicrush 10 месяцев назад +1

    Thank you so much

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

    Very good explenation 👍

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

    Thank you bro. This helped me a lot

  • @heinrichhechter7560
    @heinrichhechter7560 21 час назад +1

    Thanks a million for your video content, it really helped me clear up a lot!!! I have a quick question. Lets say you want to calculate the mean age of "males" who tested "positive" (therefore, Gender and Status need to be considered), but you have NA values in the age column, how would I type this? Where exactly do I include the function "na.rm=TRUE"? Does this come at the end of the box brackets or at the end of the parentheses?
    Kindest regards,
    Heino

    • @MinukuuTutorials
      @MinukuuTutorials  18 часов назад

      Hi Heinrich, thank you so much for your kind words. I am still passionate about biostatistics but unfortunately, my current job as a Clinical Trial Assistant does not involve any statistics, so I don't get the time to make videos on R like I used to. But thanks to words of encouragement from people like you, I will not let my statistical passion die :)
      Regarding your question, I think you should put na.rm=TRUE before closing the last bracket of the mean function.
      For example, mean(Data$Age[Data$Gender=="M"] & Data$Status=="Positive", na.rm=TRUE)

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

    amazing video!!

  • @caab6203
    @caab6203 2 месяца назад +1

    Thank you so much! I have a question: I have some NA values, so when I calculate the mean value of a column, I can give the following command to disregard those values:
    mean(columnhere, na.rm = TRUE)
    It's not working for the function to calculate a mean value based on a second factor -- I still get NA. What should I do?

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

      You are most welcome! What do you mean by based on a second factor? I just tried and it worked. Here is my code for example:
      > Base=read.csv("C:/Users/Saadong Minukuu/OneDrive/Bureau/Linotou.csv")
      > Base
      Name Grade Gender
      1 Dakurah 23 Man
      2 Maalegu NA Man
      3 Minukuu 34 Woman
      4 Saadong 45 Man
      5 Ziem 12 Man
      6 Naab NA Woman
      7 Firamwin 11 Man
      8 Bagberi 12 Woman
      > str(Base)
      'data.frame': 8 obs. of 3 variables:
      $ Name : chr "Dakurah" "Maalegu" "Minukuu" "Saadong" ...
      $ Grade : int 23 NA 34 45 12 NA 11 12
      $ Gender: chr "Man" "Man" "Woman" "Man" ...
      > as.factor(Base$Gender)
      [1] Man Man Woman Man Man Woman Man Woman
      Levels: Man Woman
      > str(Base)
      'data.frame': 8 obs. of 3 variables:
      $ Name : chr "Dakurah" "Maalegu" "Minukuu" "Saadong" ...
      $ Grade : int 23 NA 34 45 12 NA 11 12
      $ Gender: chr "Man" "Man" "Woman" "Man" ...
      > mean(Base$Grade[Base$Gender=="Man"])
      [1] NA
      > mean(Base$Grade[Base$Gender=="Man"],na.rm=T)
      [1] 22.75

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

    Thanks for the video! Do you know how I can find out the lower quartile for one particular group in R please?

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

      You're most welcome. To calculate the lower quartile for one particular group, let's say, the lower quartile of the ages of females in the dataset "Data", where the individuals for the two groups (males and females) of the variable "Gender" are coded "M" and "F", respectively, we can do that by running the following code:
      summary(Data$Age[Data$Gender=="F"])
      And the results will be presented, for example, as follows:
      Min. 1st Qu. Median Mean 3rd Qu. Max.
      11.00 12.50 19.00 18.75 25.25 26.00
      In the above example, the lower quartile is 12.50.
      Hope this helps :)

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

    Thanks for the tutorial. It is very helpful😊 So, for your same dataset, say I need to find the mean age for each sex in each respective year and finally return an output in a data frame. How would I go about that. Thanks🙂!

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

      Hi Lucy, you’re most welcome. And thank you for your question. I have noted it and will try to answer you by making another video, if possible :)

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

    Your tutorial is very helpful! If using your example, how would I find the mean age of men whose aged 15 and older?

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

      Thank you! Using my example, you can find the mean age of men who aged 15 and older by the following code:
      mean(Data$Age[Data$Gender=="M" & Data$Age>=15])
      Hope this helps :)

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

    Hello, I am from Paris also and have a question. I have a dataset with income for 100 individuals over 40 years and I want the mean & variance of income for each year and then find the one with smallest variance. How can i do that? Since in your tutorial we can one calculate for one specific case and not do it 40 times together.

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

      Greetings! Good to know you’re also in Paris. I don’t know how your data set is organised, but I have already made a video on how to calculate row mean:
      ruclips.net/video/d_hrvTPG9JA/видео.html
      Hope this helps :)

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

    Could you please tell me how can i find variance of a particular column. Column name can be ( price ) which includes price of the product so I had calculate variance of price

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

      Hi, to calculate variance in R, use the code "var". For example, if your data set read into R which contains the column "price" is named by the object "Data", for example:
      Data=read.csv(........)
      To calculate the variance of price in this data set, run the code:
      var(Data$Price).
      If the column price contains missing values, then you can use the following code:
      var(Data$Price, na.rm=TRUE)

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

    Good morning. How do you sum all attributes in a column of a large dataset of more than 100,000 records? Also, assuming the dataset is made up of exports and imports for 5 different years, how do you sum all the monetary values of exports only and imports only for a particular year? I will be glad to get your response as soon as possible because I am currently working on an assignment to submit in less than a week. If you don't mind, kindly share your telephone contact so that I will contact you for more assistance.

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

      Hi, I don't really get your question. Kindly send me your questions and the dataset via Facebook @Minukuu Tutorials, so we can discuss it in detail.

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

      I followed your procedure for finding the mean and I transferred that knowledge and was able to find the R code that returns the total attributes in the column I need. Thank you for this.

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

      @@zakariaosman3802 Great ! I am glad this tutorial helped you. Thanks for your feedback and all the best !

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

      @@MinukuuTutorials . My other problem is that the total values in the column are all numeric but they are large amounts in dollars of, for example: 104,000,000,000, 92,000,000,000, 87,000,000,000, 102,000,000,000. The column name of these attributes is "Value". I have attached million(000000) to the column and renamed it as "Value$m", where 'm' stands for million. Once the million(6 zeros) have been imbeded in the column name, it means I have to omit the 6 zeros from each of the attributes listed above so that I can manage the figures well to support my analysis. For instance, the 104,000,000,000 now becomes 104,000; the same thing appliea to the rest. I therefore need the R code to be able to remove/omit these 6 zeros from each of the amounts stated above. The numbers are real-world international trade figures. That's why they are huge. My Whassap contact is +233246990034. You can alternatively give me your contact. Thank you.

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

      As requested, please try the follwing code in order to omit the 6 zeros from the new values column, which I named "Value_million":
      Data

  • @jamesmettle2
    @jamesmettle2 Год назад +2

    bruh just go straight to the point.......26mind for calculating mean?//come on bruh