필터 지우기
필터 지우기

Joining two tables with two common columns

조회 수: 14 (최근 30일)
Wesso
Wesso 2020년 6월 21일
댓글: Wesso 2020년 6월 21일
Hi ,
I have two tables A and B. They have two common columns:
A's columns are Date, ID, col1, col2 etc...
B's columns are Date, X1, ID, X2 etc....
Columns 1 and 2 of A match columns 1 and 3 from B. "tried join, innerjoin functions and received errors probably because A and B have multiple columns that are different:. My question is how to produce table C that has every row in A and the rows of B that match those of A .So C would be somethings like [ Date,ID, col1,col2 ,X2,X2,etc...];I don't want the columns 1 and 3 in B to be reproduced (so, I don't want C to appear like [ Date1,ID1, col1,col2 ,Date2,ID2,X2,X2,etc...] and I want the rows of A that are not matched by B to have nans .
I am wondering what is the right command for this :
Dor example I tried
C= innerjoin(A,B,,'LeftKeys',[1,2],'RightKeys',[1,3]);
I received:
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for
mismatched delimiters.
  댓글 수: 2
dpb
dpb 2020년 6월 21일
The error message is just a syntax problem -- you've got an extra comma in there...
I've never wrapped my head around inner/outer join so whether it'll do what you want or not I dunno', but
C= innerjoin(A,B,'LeftKeys',[1,2],'RightKeys',[1,3]);
should at least produce something...
Wesso
Wesso 2020년 6월 21일
great it works.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by