Tidyverse gather with rowdata from other data frame

前端 未结 1 1628
忘了有多久
忘了有多久 2021-01-24 11:58

I have been searching for quite some time to an elegant solution to this problem, to no avail. So I decided to give it a go here.

I am using tidyverse, and

相关标签:
1条回答
  • 2021-01-24 12:28

    The *_join functions from dplyr (loaded with tidyverse) are great for solving lots of problems involving more than one dataframe.

    > df %>%
          gather(sample, value, -annot) %>%
          left_join(sample_info, by = 'sample')
    
      annot  sample value  condition
    1     A sample1     1   infected
    2     B sample1     1   infected
    3     C sample1     4   infected
    4     D sample1     2   infected
    5     A sample2     3 uninfected
    6     B sample2     5 uninfected
    7     C sample2     4 uninfected
    8     D sample2     5 uninfected
    
    0 讨论(0)
提交回复
热议问题