Calculating ratios by group with dplyr

后端 未结 1 1906
攒了一身酷
攒了一身酷 2021-01-19 07:26

Using the following dataframe I would like to group the data by replicate and group and then calculate a ratio of treatment values to control values.

structu         


        
1条回答
  •  [愿得一人]
    2021-01-19 07:41

    You can try:

    group_by(dataIn, replicate) %>% 
        summarise(ratio = quant[group=="case"]/quant[group=="controls"])
    #Source: local data frame [4 x 2]
    #
    #  replicate    ratio
    #1      four 1.078562
    #2       one 1.333333
    #3     three 1.070573
    #4       two 1.446449
    

    Because you grouped by replicate and group, you could not access data from different groups at the same time.

    0 讨论(0)
提交回复
热议问题