Reshaping data in R to be long or wide with pivot_longer and pivot_wider (CC185)

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ย. 2024

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

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

    Thanks a bunch for this series. Your videos are really clear, and practical. I’ve recommended your videos to everyone on my team!

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

      Wonderful! Thanks for spreading the word 😊

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

    The MANNNNNN

  • @hope2024-g
    @hope2024-g ปีที่แล้ว

    Thank you Sir for the nice tutorial. How can I convert pairwise distance matrix data (Bray-Curtis pairwise dissimilarity matrix) into continues variable Please ? I have collected plant species diversity and biomss from 25 sites. I want to assess relationship between Biomass and Beta diversity in r. As you know the biomass data from 25 sites is continues variable, while the Bray-Curtise pairwise distance data is a matrix. So how can I make linear regression using these Biomass as response variable and Bray-Curtis dissimilarity (beta diversity) as predictor Please ? Your help will be highly appreciated!

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

    Thank you for this video! And of course for advice and help earlier. The video was already shared with the other people in my department.

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

    good ideas for matrix diagonal extraction for PCA

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

      Thanks for watching!

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

    I love the trick of comparing two character strings using < or >. Very nice.

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

      You have to think a little about what’s going on but it’s pretty slick. Thanks for watching!

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

    I am confused as to which package *pivot_** functions belong to. I thought that should be *tidyr* but I realized the functions still work fine with only *dplyr* loaded.

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

      Hi Caty! It is tidyr but I’m sure dplyr uses tidyr as a dependency to work with tibbles

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

      @@Riffomonas Yeah, that might be the case then. I strive not to load the the whole *tidyverse* thing; I like to keep my environment lean that way. So, I have to know where every function I call comes from.

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

      @@caty863 I think you could do tidyr::pivot_longer to load only that function without calling library(dplyr) or library(tidyr)

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

    Thank you so much, Pat!!!! As a beginner to R, this video was very easy to follow & helped me transform my data into a dist matrix. I am so appreciative!!

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

    Amazing video again! It took longer this time , didn't it? :)) Dear Pat! What happens if we want to repeat a multiple linear regression model like this lm(y ~ SNP[i] + biomarker[p]) for all the combinations of (i, p) -> (e.g if we have i=200 SNPs' dosage level and p=100 different quantitative traits like biochemical lab tests), so that we want to do sth like sensitivity analysis and take the Regression coefficients and their corresponding Pvalues in a neat and tidy dataframe for our publication. Map2_df does not work because it does not work like 2x for loop! Any idea will be appreciated, or even it's a great exercise for next videos to scale up more our advanced functioning and object oriented programming skills. Many thanks! Dariush

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

      Couldn't you use the broom package? You could run the 200 lms in a listed df and extract all the values you need. After that, you can use gtable:: to create a neat table

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

      I think Hadley or David Robinson have a video somewhere talking about this.

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

      @@sven9r Thank you so much for your suggestion. I've seen it in map functions manual in the help section, but I did not try it. I actually tried to run it by using subsequentially lapply and map, and then write another function to make the raw output in my desired format. I can later share my solution in my Github. Many thanks :)

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

      @@Riffomonas I'm seeking for it in David's channel but I don't think I can find it :( Thanks BTW

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

      @@Riffomonas I think you meant this talk by Hadley Wickham on "Managing many models with R". Sure, I'll have look again, maybe it's better to make up my mind again and apply their approach.