親愛的社區我有一個問題,那就是如何消除第一個重複的行。
例子
| 天然橡膠 | 日期 | 數數 |
| 4567 | 2017-01-21 | 1個 |
| 5555 | 2017-02-03 | 1個 |
| 5555 | 2017-02-10 | 2個 |
| 8745 | 2015-03-10 | 1個 |
| 8345 | 2016-05-01 | 1個 |
| 9563 | 2016-01-02 | 1個 |
| 9563 | 2016-01-10 | 2個 |
在這個例子中,是否有一個腳本如何找到我在此處用粗體文本標記的重複項,並直接刪除這些行或創建一個額外的列,例如保留和消除?
我正在使用 JMP Pro 14.0.0(64 位)
您忠誠的
醫學博士 Lars Enochsson, 博士
外科教授
外科和圍手術期科學系
於默奧大學
瑞典膽結石手術和 ERCP 登記處負責人 GallRiks
瑞典外科學會科學秘書
電子郵件: lars.enochsson@umu.se
@多發性硬化症,
您多年的 JMP 經驗和知識在您的社區討論回復中顯而易見。我非常感謝您參與社區。
吉姆
實際上,我於 1994 年在瑞典烏普薩拉大學第一次接觸到 JMP,並從那時起就一直在使用它。 即使 JMP 在瑞典學術界仍然不是很常用,但我已經“轉換”了相當多的 SPSS 用戶。
同意,這個社區很棒。
這個腳本也應該工作:
// Delete all multiplicate rows except the one with the latest date (sorting does not matter).
dt = Current Data Table();
dt << Select Where(Col Max(:Date, :Nr) > :Date);
dt << Delete rows;
編輯:如果重複項可以具有相同的日期,則效果更好,但需要按日期排序。
dt << Select Where(Col Max(Row(), :Nr) > Row());
dt << Delete Rows;
這是一個可以完成工作的腳本:
Names Default To Here( 1 );
dt = New Table( "Example",
Add Rows( 7 ),
New Script(
"Source",
Data Table( "Transpose of Untitled 17" ) <<
Subset( All rows, Selected columns only( 0 ) )
),
New Column( "Nr",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [4567, 5555, 5555, 8745, 8345, 9563, 9563] )
),
New Column( "Date",
Numeric,
"Continuous",
Format( "yyyy-mm-dd", 12 ),
Input Format( "yyyy-mm-dd" ),
Set Values(
[3567801600, 3568924800, 3569529600, 3508790400, 3544905600, 3534537600,
3535228800]
)
),
New Column( "Count",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 1, 2, 1, 1, 1, 2] )
)
);
dt << select duplicate rows( Match( :Nr ) );
wait(5);
dt2 = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
dt << delete rows;
Wait(5);
dt = dt << Update( With( dt2 ), Match Columns( :Nr = :Nr ) );
Close( dt2, nosave );
嗨拉斯,
重複項是否總是按順序排列,或者它們之間是否有記錄?如果它們總是像您的示例中那樣順序排列,您可以執行以下操作:
dt = Current Data Table();
del_rows = {}; //initiate list to contain list of rows that are duplicates
for(i = 1, i<=N Row(dt), i++,
if(:Nr[i] == :Nr[i+1], insert into(del_rows,i)) //if Nr for current row is same as next, then put current row in del_rows
);
dt << Delete Rows(del_rows); //delete all rows in del_rows