Table Find Duplicate Rows (double, char, datetime)

조회 수: 186 (최근 30일)
Dave
Dave 2021년 10월 25일
편집: the cyclist 2021년 10월 26일
Hello, in table A with 100,000 rows and 40 columns, is there a way to find duplicate rows?
The elements are of the type: double, char, datetime
Thanks

답변 (1개)

the cyclist
the cyclist 2021년 10월 25일
You might need to share some more details about your table, but you should be able to use the unique function.
% Make some pretend data, which is 8 rows with 4 unique ones
tbl = array2table([magic(4); magic(4)]);
% Find the unique rows, along with indices for identifying the duplicates
[uniqueTableRows,indexToUniqueRows,indexBackFromUnique] = unique(tbl);
See the documentation for details on the indices that are reported.
  댓글 수: 2
Dave
Dave 2021년 10월 26일
편집: Dave 2021년 10월 26일
The table has double in some columns, char in some columns, datetime in one column
If I use unique it brings the same number of rows (and I check in excel that some rows are identical)
the cyclist
the cyclist 2021년 10월 26일
편집: the cyclist 2021년 10월 26일
Different data types should not be a problem with this method:
% Make some pretend data of different types
n = [1; 2; 1; 1; 2; 1];
c = {'a';'b';'a';'b';'a';'b'};
t = datetime({'2014-05-26';'2014-08-03';'2014-05-26';'2014-08-03';'2014-05-26';'2014-08-03'},'InputFormat','yyyy-MM-dd');
% Put them in a table
tbl = table(n,c,t)
tbl = 6×3 table
n c t _ _____ ___________ 1 {'a'} 26-May-2014 2 {'b'} 03-Aug-2014 1 {'a'} 26-May-2014 1 {'b'} 03-Aug-2014 2 {'a'} 26-May-2014 1 {'b'} 03-Aug-2014
% Find the unique rows, along with indices for identifying the duplicates
[uniqueTableRows,indexToUniqueRows,indexBackFromUnique] = unique(tbl)
uniqueTableRows = 4×3 table
n c t _ _____ ___________ 1 {'a'} 26-May-2014 1 {'b'} 03-Aug-2014 2 {'a'} 26-May-2014 2 {'b'} 03-Aug-2014
indexToUniqueRows = 4×1
1 4 5 2
indexBackFromUnique = 6×1
1 4 1 2 3 2

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

카테고리

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