我希望這個功能存在,如果沒有的話將是一個很好的補充。 我正在尋找使用變數執行矩陣運算的能力。 據我所知,目前此功能僅存在於數據表中。 擁有此功能將能夠在不使用循環的情況下對矩陣進行排序。
A = Random Index(10^4,10^2);
B = Shape(A,10,10);
C = Sort Descending(B); // Fails since function only supports vector or list
D = Rank(B);// Fails since function only supports vector or list
@gzmorgan0 ,
你的解釋相當準確。 我同意 JMP 提供的觀點一些按列功能。 我的要求是擴展這些超越平均值和總和的範圍。
在實現這些函數時,如果可以避免的話,我不想使用循環。 如果內建函數已經使用它,通常它們會被最佳化,我對此表示同意。 但是,如果有可能避免使用循環,我會想避免它。
現在關於排名和排序,我見過的按行排序的另一種語言是在 Matlab 中( https://www.mathworks.com/help/matlab/ref/sort.html )。 我也一直在嘗試學習 SAS,我所看到的一件事是在 SAS 中,為了獲得排名,您對資料集進行排序並添加實際上有意義的行號。 因此,我在 JMP 中對行排序和排名的請求背後的意圖是能夠擁有這樣的槓桿作用,用戶可以對資料集進行排序,並使用 row() 函數自動獲得排名順序。
我一直在研究上述請求的用途的一個例子是對時間序列資料進行排名(每小時/每天/每週)。
目前,我知道如何在此類資料集上實現排名的唯一方法是將其帶回資料表並使用 Col Rank() 和 Col Rank() 和 Col Number()。
A = Random Shuffle(Random Index(10^3,240)); // random hourly data for 10 days
dt = As Table(A);
As Column(dt,"Col1") << Set Name("TestVal");
dt << New Column("Day",Numeric,Continuous,Formula(Ceiling(Row()/24)))
<< New Column("RankHourByDayAsc",Numeric,Continuous,Formula(Col Rank(:TestVal,:Day)))
<< New Column("RankHourByDayDesc",Numeric,Continuous,Formula(Col Number(:TestVal,:Day) + 1 - Col Rank(:TestVal,:Day)));我假設您的“按變數”請求是按列。 JMP 已提供多種按列功能:V Mean、V Min 等。
我看到了 V Rank 的好處,但 V 降序排序會很奇怪。創建矩陣(使用 Shape 或 Get as Matrix 創建)後,通常,行中的項目會“連結”,即保持在一起。 您對降序排序(B) 有何期望? 我並不了解所有語言,但我只在Matlab中見過按行排序,它使用行中的第一個元素來指定行順序。 您是否有另一種語言或統計套件中的範例可以排序但不維護行連結?
以下是 ByColMat() 函數的範例。 取消註釋“用法”,然後進行測試。 注意降序排序會破壞行鏈接
Names Default to Here(1);
//=================================================================================
byColMat = Function({mat, expr_name}, {nc, imat, i, rslt},
//mat is a matrix, expr_name is a string of a valid vector function
//returns a matrix typically a row vector if the name_expr function returns 1 value
//or a matrix ofd the same size. Summary is a special case
nc = ncol(mat);
if(expr_name=="Summary",
imat=J(10,nc,empty());
imat[1,0] = V Mean(mat);
imat[2,0] = V Std(mat);
imat[3,0] = V Min(mat);
imat[4,0] = V Max(mat);
imat[5,0] = V Sum(mat);
For(i = 1, i<=nc, i++,
imat[6,i] = Quantile(.25, mat[0,i]);
imat[7,i] = Quantile(.50, mat[0,i]);
imat[8,i] = Quantile(.75, mat[0,i]);
imat[9,i] = imat[8,i] - imat[6,i];
imat[10,i] = nc - Nmissing(mat[0,i]);
);
Write("Stats are: Mean, Std Dev, Min, Max, Sum, Q25, Median, Q75, IQR, N");
, //else
imat=[];
mexpr = parse(expr_name || "(mat[0,i])");
For(i = 1, i<=nc, i++,
imat ||= eval(mexpr)
);
);//end if
imat
); //end function
/* Usage Example
//create a random matrix to emulate a data matrix
A = J(10,10, RandomInteger(1,10^4));
show(A, byColMat(A, "Summary"));
show(A, byColMat(A, "Sort Descending"));
show(A, byColMat(A, "Rank"));
*/