Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>data.table</code> package (that allows for x[y] syntax) makes this job incredibly easy. Assuming <code>df1</code> and <code>df2</code> are your data.frames:</p> <pre><code>require(data.table) dt1 &lt;- data.table(df1, key=c("V1","V2","V3")) dt2 &lt;- data.table(df2, key=c("V1","V2","V3")) dt2[dt1] # V1 V2 V3 V4 # 1: T1 A1 B1 1 # 2: T1 A1 B2 NA # 3: T1 A2 B1 3 # 4: T1 A2 B2 1 # 5: T2 A1 B1 2 # 6: T2 A1 B2 2 # 7: T2 A2 B1 3 # 8: T2 A2 B2 2 </code></pre> <p>gives you the desired result.</p> <p><strong>Edit:</strong> I've used your edited data and it seems to work.</p> <pre><code>df1 &lt;- structure(list(V1 = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("T1", "T2"), class = "factor"), V2 = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c("A1", "A2"), class = "factor"), V3 = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("B1", "B2"), class = "factor")), .Names = c("V1", "V2", "V3"), class = "data.frame", row.names = c(NA, -8L)) df2 &lt;- structure(list(V1 = structure(c(1L, 1L, 2L, 1L, 2L, 2L, 2L), .Label = c("T1", "T2"), class = "factor"), V2 = structure(c(2L, 2L, 2L, 1L, 1L, 2L, 1L), .Label = c("A1", "A2"), class = "factor"), V3 = structure(c(2L, 1L, 1L, 1L, 2L, 2L, 1L), .Label = c("B1", "B2"), class = "factor"), run.no = 1:7, run.no.std.rp = structure(c(3L, 7L, 6L, 4L, 5L, 2L, 1L), .Label = c("C0.15", "C0.16", "C0.17", "C0.3", "C0.4", "C0.6", "C0.7"), class = "factor"), Block.ccd = c(0L, 0L, 0L, 0L, 0L, 0L, 0L), A = c(400L, 450L, 350L, 450L, 350L, 350L, 450L), B = c(147.5, 120, 175, 120, 120, 120, 120), C = c(5L, 2L, 2L, 8L, 8L, 2L, 2L), D = c(2.675, 4, 4, 4, 4, 1.35, 1.35)), .Names = c("V1", "V2", "V3", "run.no", "run.no.std.rp", "Block.ccd", "A", "B", "C", "D"), row.names = c("C0.17", "C0.7", "C0.6", "C0.3", "C0.4", "C0.16", "C0.15"), class = "data.frame") require(data.table) dt1 &lt;- data.table(df1, key=c("V1", "V2", "V3")) dt2 &lt;- data.table(df2, key=c("V1", "V2", "V3")) dt2[dt1] # V1 V2 V3 run.no run.no.std.rp Block.ccd A B C D # 1: T1 A1 B1 4 C0.3 0 450 120.0 8 4.000 # 2: T1 A1 B2 NA NA NA NA NA NA NA # 3: T1 A2 B1 2 C0.7 0 450 120.0 2 4.000 # 4: T1 A2 B2 1 C0.17 0 400 147.5 5 2.675 # 5: T2 A1 B1 7 C0.15 0 450 120.0 2 1.350 # 6: T2 A1 B2 5 C0.4 0 350 120.0 8 4.000 # 7: T2 A2 B1 3 C0.6 0 350 175.0 2 4.000 # 8: T2 A2 B2 6 C0.16 0 350 120.0 2 1.350 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload