Proportions with dplyr Package in R (Example) | Create Relative Frequency Table in RStudio

Поделиться
HTML-код
  • Опубликовано: 21 авг 2024

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

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

    Hi, I had the same result from a slightly different code:
    data%>%
    group_by(x)%>%
    count(y)%>%
    mutate(freq = n / sum(n))
    I appreciate your videos so much. I also learn a lot from Q&A in these comments. Thanks a million.

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

      Thank you so much for the very kind words Khang, glad you find my tutorials useful! Also, thanks a lot for sharing your alternative code!

  • @agsoutas
    @agsoutas 3 года назад +2

    The uses of this code must be really interesting, I will apply this to work!

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

      Glad to hear that, I hope it will help you daily workflow :)

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

    Thank you

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

    very useful

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

    Thanks a lot!

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

    R! How is that different from:
    data1 %>%
    count(X,Y) %>%
    group_by(Y) %>%
    mutate(prop = prop.table(n) * 100) ? Love your videos :)

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

      Hello Larissa,
      In the tutorial, the frequency of ys is calculated relative to xs, in your code, the frequency of xs is calculated with respect to the ys.
      Regards,
      Cansu

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

      @@cansustatisticsglobe Thank you very much!

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

      @@larissacury7714, You are welcome!

  • @RockenBonkers
    @RockenBonkers 3 года назад +4

    Can you use this info to create a histogram, and if so, how do you do that?

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

      Hey Ruqayah, Histograms are usually not created based on frequencies of categorical variables. You may create a barplot though. Have a look here: statisticsglobe.com/barplot-in-r Regards, Joachim

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

      @@StatisticsGlobe I just renamed the variable and then could reference it. Also, thanks for the reference.

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

      You are welcome :)

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

    So, what if you wanted to know, for example, what proportion of 1 is A?

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

      Hey Jesse, the table created in the video shows the proportions within each group of the variable x. In case you want to know the frequency of 1 A relative to the entire data frame, you can use the following code:
      data2

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

    If you have a tibble, inside the tibble is a column of percentages that I want to extract as proportions.
    How do I do that?

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

      Hey Angelica, generally speaking, you can extract columns using the $ operator (e.g. data$x). Could you illustrate how the values in your column look and how the output should be formatted? Regards, Joachim

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

      @@StatisticsGlobe I'm using the midwest date set and in the one column I have percollege which is percentage of people that went to college and I want to extract that into my tibble, but i need it to show me the proportion of college educated people.

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

      So the values in your data look like that "25%" and you want to convert it to that "0.25"?

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

      @@StatisticsGlobe yes, but I need to do that and extract it from the existing tibble into a new tibble.

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

      Please have a look at the following example code:
      library("tidyverse")
      tibble1