Combining conditional data in Mathematica

I need to combine data from two different sources . The tables below show what I have:

enter image description here

And the desired conclusion:

enter image description here

The idea is this:

  • Look at the first column. table 1 (TrialNO)

  • Look for it in the first column. table 2.

  • Make sure the values ​​in the second column. equal (in fact, these col. will not be in the same places in 2 lists)

  • If Check is pass adds the values ​​located in col. 3 and 4 (Cond1 and Cond2) to the row in table 2.

  • I don’t think that I will store the headers in a real structure, therefore it should not present an additional problem, but suggestions on working with headers are welcome (should they be deleted and stored in another place or should they be processed in a special way)

**

EDIT:

**

, , . , . , .

( ), .

  • 3 . 2AFC ( ).
  • ( 1/4 ) 8 , 1 4 .
  • 5 , , , , 10 (1 ).
  • 2 : , .

:


  • "" ,

- /

-

-Conditions

-Subject Answer

-X Y, 11 , .

Display, DisplayNO 1 400 (1,2,3,4,..., 400), TrialNO 1 200 (1,1,2,2,.., 200 200) 2 .


  • "Eye-Tracking" , :

- ( ( 1 400), 2, , . 2)

, :

- , , .. ( 100 )

. ( ). 1 30-50 . 19 5 .


  • 2, , .

  • , .

( ):

  • .

  • - ( , , ...), -Display Info ( ), -Fixations info ..

  • (String, Number, text), , , , .

  • (: , , ) , , , .

, , , .

+3
3

.

checkMerge[src_, trg_, si_, ti_, sp_] :=
 Module[{rls, ext},
  rls = #[[si]] -> #[[sp]] & /@ src;
  AppendTo[rls, _ -> {,}];
  ext = Replace[trg[[All, ti]], Dispatch@rls, 1];
  ArrayFlatten[{{trg, ext}}]
 ]

:

  • src= "" (data1)
  • trg= "" (data2)
  • si=
  • ti=
  • sp=

:

checkMerge[data1, data2, {1,2}, {1,2}, {3,4}]

, :

( col. 2 )

, .

  • sp ( ) , , , . , data1 data2, , - ?

  • si, ti, sp, , , .

  • , , Null, ; , , .

+2

:

MergeTables[data1_, data2_, samepos1_, samepos2_] :=
 Cases[data1, 
  x_ :> Block[{y = 
      Cases[data2, z_ /; z[[samepos2]] === x[[samepos1]]]},
    Apply[Sequence, Join[x, Delete[#, Thread[{samepos2}]]] & /@ y]]]

:

MergeTables[data2, data1, {1, 2}, {1, 2}]
+5

, , .

Here is my attempt and, as a structural more functional programmer, I used the table [] (OMG!) To do this. Well, table [] is still on the verge of functional programming :)

(Here A is data2, and B is data1)

n=Length[A];  m=Length[B];

isMatch[a_,b_] := a[[1]]=== b[[1]]&&a[[2]]===b[[2]]

A[[1]] = A[[1]]~Join~B[[1,3;;-1]]; (*do the header on its own*)

Table[If[ isMatch[B[[i]],A[[j]]], 
          A[[j]] = Join[A[[j]],B[[i,3;;-1]]] 
     ],

     {i,2,m},{j,2,n}        
];

A//TableForm

- Nasser

+1
source

All Articles