Merging a dataset with entries for every day with the other one with entries only for weekdays

조회 수: 1 (최근 30일)
I have two datasets. The first one has data for every day. The second one has entries and data only for weekdays. How can I merge these two datasets so that the outcome file with entries for every day?

채택된 답변

Sammit Jain
Sammit Jain 2018년 5월 23일
I think what you're trying to accomplish is well-documented here, as a special case of the outerjoin function.
For example, consider your table A
A = table({'a' 'b' 'c' 'e' 'h'}',[1 2 3 11 17]',...
'VariableNames',{'Key1' 'Var1'})
Key1 Var1
____ ____
'a' 1
'b' 2
'c' 3
'e' 11
'h' 17
And now consider another table B
B = table({'a','b','d','e'}',[4;5;6;7],...
'VariableNames',{'Key1' 'Var2'})
Key1 Var2
____ ____
'a' 4
'b' 5
'd' 6
'e' 7
Notice that the first column in both tables has some entries in common with the other and some not. This is a direct analogy to your weekday and all days example.
C = outerjoin(A,B,'MergeKeys',true)
After this, your table C will have the merged dataset/table.
Key1 Var1 Var2
____ ____ ____
'a' 1 4
'b' 2 5
'c' 3 NaN
'd' NaN 6
'e' 11 7
'h' 17 NaN
Here you can explore more options in the outerjoin documentation to filter your data into exactly one column if needed.
  댓글 수: 2
alpedhuez
alpedhuez 2018년 5월 23일
But I want to outerjoin only using dates (Key1) but not using other keys. Please advise.
Sammit Jain
Sammit Jain 2018년 5월 23일
There are options in the outerjoin function that you can try configuring. See here - https://www.mathworks.com/help/matlab/ref/outerjoin.html Alternatively, once you have combined data, you can filter it out depending on your requirements.

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

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by