1

I've got about 30 datatables. Now I want to find overlaps in the first column in some of the tables and extract them. The result should be a table with the overlaps in the first column from more than two datatables. Here's an example:

Table1:

Gen          Estimate    Std. Error    p-Wert
1007_s_at    -0.159699   0.07834       0.04265
1053_at      -0.174647   0.064535      0.0098976
121_at       0.1765678   0.05116854    0.0000657

Table2:

Gen        Estimate     Std. Error   p-Wert
1494_f_at  0.2222467    0.0553653    0.0075838
121_at     0.873683     0.00898737   0.0088378
1316_at    0.098764     0.098456     0.048899
1007_s_at  0.89723      0.5675389    0.00007865

Table3:

Gen        Estimate     Std.Error    p-Wert
1007_s_at  0.0864567    0.8931278    0.005542
121_at     0.2378590    0.0236586    0.00005667
1494_f_at  0.4597023    0.9875357    0.0091234

The result should be:

Gen      
1007_s_at
121_at

I tried the foverlaps function, but that's only for two datatables. So it didn't work.

I hope someone could help. Thanks!

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • Nice question. **But**, have you tried anything before posting this question ? Can you share your code, please ? – akash Aug 24 '16 at 13:06
  • Welcome to StackOverflow. The question is well asked with a clear example. Unfortunately, you must show what you have tried so far before asking for help. – Arnaud Denoyelle Aug 24 '16 at 13:06

1 Answers1

1

I think for this you want to use set operations.

Set Operations

This should work:

dat1 <- data.frame(gen = c("aaaaa", "1494_f_at", "1111", "!!!!"), stringsAsFactors = FALSE)

dat2 <- data.frame(gen = c("1494_f_at", "cccccc", "!!!!","999"), stringsAsFactors = FALSE)

dat3 <- data.frame(gen = c( "!!!!","1494_f_at", "999", "dddddd"), stringsAsFactors = FALSE)

intersect(intersect(dat1[,1], dat2[,1]), dat3[,1])
USER_1
  • 2,409
  • 1
  • 28
  • 28
  • But when I have more than 3 dataframes it will be too nested. Is a loop possible? – Melanie Julia Aug 24 '16 at 19:48
  • In that case you should probably do something like this: Reduce(function(x, y) merge(x, y, all=TRUE), list(df1, df2, df3)) - from this question http://stackoverflow.com/questions/14096814/r-merging-a-lot-of-data-frames – USER_1 Aug 24 '16 at 20:57