ranalysis

Loop two data frames to make meta analysis


I have DF1 and DF2 with equal dimension, for example,

DF1
hr  se         m
1   0.5   1.5  a 
2   1.5   2.5  b
3   2.5   3.5  c
4   3.5   4.5  d

DF2
hr  se         m
5   4.5   5.5  a
6   5.5   6.5  b
7   6.5   7.5  c
8   7.5   8.5  d

I need to make meta analysis. I know that for all rows of one DF, i can make it as

library(rmeta)
d <- meta.summaries(DF1$hr, DF1$se, names = DF1$m, method = c("fixed"))

But what i want is to make meta analysis for every row of these two data frames. For example, row 1 of DF1 is meta analysed with row 1 of DF2. I might suppose that i need loop or lapply function. Thank you for any tips or suggestions.


Solution

  • One option would be to just use rbind and then split by m to get a list:

    df3 <- rbind(df1, df2)
    split(df3, df3$m)
    
    $a
      hr  se   x m
    1  1 0.5 1.5 a
    5  5 4.5 5.5 a
    
    $b
      hr  se   x m
    2  2 1.5 2.5 b
    6  6 5.5 6.5 b
    
    $c
      hr  se   x m
    3  3 2.5 3.5 c
    7  7 6.5 7.5 c
    
    $d
      hr  se   x m
    4  4 3.5 4.5 d
    8  8 7.5 8.5 d
    

    You can then use a for loop or lapply to get the results. For that, just Google for for loop R or apply family R.