title: Comparing two data sets in R
body: <p>I've searched around here and google for hours and cannot find a solution to my problem.</p>
  
  <p>I have two datasets containing genes. One dataset is my dataset (snap) and I need to see if these genes are in the second bigger data set (catalog). I want the second column in snap (proxy) and the 21st column from catalog. This is what my datasets look like;</p>
  
  <pre><code>&gt; head(snap)
          SNP     Proxy Distance RSquared DPrime
  1 rs4246511 rs7540233     4541    0.874      1
  2 rs4246511 rs4970634    15768    0.874      1
  3 rs4246511 rs4532801    18960    0.874      1
  4 rs4246511 rs9438982    22242    0.874      1
  5 rs4246511 rs9438979    25034    0.874      1
  6 rs4246511 rs4414011    25868    0.874      1 
  
  head(catalog)
          SNPS MERGED SNP_ID_CURRENT    CONTEXT INTERGENIC
  1  rs7079041      0        7079041     intron          0
  2  rs7244261      0        7244261 intergenic          1
  3 rs10448044      0       10448044 intergenic          1
  4  rs2610025      0        2610025 intergenic          1
  5  rs1472147      0        1472147     intron          0
  6  rs2648708      0        2648708     intron          0
  </code></pre>
  
  <p>*This is a small part of the datasets</p>
  
  <p>To make it more complicated, I'd also like to be able to pull the whole row of data from both data sets.</p>
  
  <p>For the first part of my question I have tried using comparison (which I found from another similar question here). I decided to extract the columns I needed to simplify things (proxy is my column from snap and catalogsnps is the column from catalog);</p>
  
  <pre><code>    comparison &lt;- compare(proxy, catalogsnps, allowAll=TRUE)
  comparison$tM
  
  difference &lt;- data.frame(lapply(2:ncol(proxy),function(i)setdiff(cacheGenericsMetaData[,i],comparison$tM[,i])))
  colnames(difference) &lt;- colnames(proxy)
  write.table(difference, file="difference.csv", sep=";", dec=".")
  </code></pre>
  
  <p>However with this syntax my output is simply a list of all my SNPs from snap.</p>
  
  <p>Output </p>
  
  <pre><code>1054  6267
  1055  6273
  1056  6297
  1057  6297
  1058  6314
  1059  6331
  1060  6340
  1061  6345
  1062  6346
  1063  6350
  1064  6364
  1065  6412
  1066  6417
  1067  6417
  1068  6430
  </code></pre>
  
  <p>Since this was hard to read, I added the line to get the excel file, this looks like this;</p>
  
  <pre><code>x   
  1   rs7079041
  2   rs7244261
  3   rs10448044
  4   rs2610025
  5   rs1472147
  6   rs2648708
  7   rs11891
  8   rs1801725
  9   rs6852678
  10  rs3135758
  11  rs6838240
  12  rs6838240
  13  rs603894
  14  rs3764796
  15  rs3764796
  16  rs2073214
  17  rs4971100
  18  rs4971100
  19  rs11718502
  20  rs10888073
  21  rs7032317
  </code></pre>
  
  <p>I also found another possible solution on here, but I again only got a list of my SNPs. </p>
  
  <pre><code>rows.diff &lt;- function(catalog, proxy)
  {
    catalogsnps.vec &lt;- apply(catalogsnps, 1, paste, collapse="")
    proxy.vec &lt;- apply(proxy, 1, paste, collaspse= "")
    rows.diff &lt;- catalogsnps[!catalogsnps.vec %in% proxy.vec,]
    return(rows.diff)
  }
  write.table(rows.diff(catalogsnps, proxy), file="rowdiff.csv", sep=";", dec=",")
  </code></pre>
  
  <p>For the second part of my question, I am completely lost about where to start</p>
  
  <p>Many thanks for any help</p>
  
  <p>Claire</p>