필터 지우기
필터 지우기

Find min and max datetime in table

조회 수: 60 (최근 30일)
Frederick Awuah-Gyasi
Frederick Awuah-Gyasi 2022년 5월 19일
댓글: Voss 2022년 5월 19일
table
A , Datetime,
2 05/20/22
2 05/20/23
3 04/12/99
3 06/12/02
the goal is to have two more columns with min and max dates
table
A , Datetime, Min, Max
2 05/2/22 05/2/22 05/2/23
2 05/2/23 05/2/22 05/2/23
3 04/12/01 04/12/01 06/12/02
3 06/12/02 04/12/01 06/12/02
I was tring table_min = groupsummary (table,{table.A,table.Datetime}, 'min'}
table_max= groupsummary (table,{table.A,table.Datetime}, 'max'}
So I join this date to table but i'm getting an error :
[groupingData,groupVars] = matlab.internal.math.parseGroupVars(groupVars,tableFlag,'groupsummary',T);
Thank you.

채택된 답변

Voss
Voss 2022년 5월 19일
T = table( ...
[2;2;3;3], ...
datetime({'05/20/22';'05/20/23';'04/12/99';'06/12/02'},'InputFormat','MM/dd/yy'), ...
'VariableNames',{'A' 'Datetime'})
T = 4×2 table
A Datetime _ ___________ 2 20-May-2022 2 20-May-2023 3 12-Apr-1999 3 12-Jun-2002
table_min = groupsummary (T, 'A', 'min')
table_min = 2×3 table
A GroupCount min_Datetime _ __________ ____________ 2 2 20-May-2022 3 2 12-Apr-1999
table_max = groupsummary (T, 'A', 'max')
table_max = 2×3 table
A GroupCount max_Datetime _ __________ ____________ 2 2 20-May-2023 3 2 12-Jun-2002
g = findgroups(T.A)
g = 4×1
1 1 2 2
T.Min = table_min{g,'min_Datetime'};
T.Max = table_max{g,'max_Datetime'};
T
T = 4×4 table
A Datetime Min Max _ ___________ ___________ ___________ 2 20-May-2022 20-May-2022 20-May-2023 2 20-May-2023 20-May-2022 20-May-2023 3 12-Apr-1999 12-Apr-1999 12-Jun-2002 3 12-Jun-2002 12-Apr-1999 12-Jun-2002
  댓글 수: 2
Frederick Awuah-Gyasi
Frederick Awuah-Gyasi 2022년 5월 19일
편집: Frederick Awuah-Gyasi 2022년 5월 19일
Thanks so much. life saver.
Voss
Voss 2022년 5월 19일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by