cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
] />

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
TamedZebra
Level III

Calculating Mode for String Data with Grouping

I attempted to calculate the mode of column A, grouped by column B, using the Col Mode(:A,:B) function. However, since column A contains string data, no value was output. I then discovered that Mode(:A) can obtain the mode even for string data. The problem now is that I don't know how to perform the grouping. How should I construct the formula?

11 REPLIES 11
TamedZebra
Level III

Re: Calculating Mode for String Data with Grouping

// データテーブルを取得
dt = Current Data Table();
process_nm = "A";

// B列のユニークな値を取得(グループ化のため)
unique_groups = dt:B << Get values;

// 新しい列 "mother" を作成
dt << New Column("mother", Character, "Nominal");

// 各グループごとに処理を実行
For(i = 1, i <= N Items(unique_groups), i++,
    // 現在のグループをフィルタリング
    current_group = unique_groups[i];
    subset_rows = dt << Get Rows Where(:B == current_group);
    // A列のキーを取得
    score_indices = Associative Array(Set Unique(Column(process_nm)[subset_rows])) << get keys;
    // グループ内の "mother" 列を更新
    dt:mother[subset_rows] = Mode(Column(process_nm)[subset_rows]);
);

Calculating Mode for String Data with Grouping

・Col Mode()は文字列には対応していない

・Mode()は文字列に対応している

・Mode()はグルーピングに対応していない

【対策】

1.文字列を数値のように扱い、Col Mode()を使用する。

2.予め行を絞り込み、Mode()を使用する。

hogi
Level XIII

Re: Calculating Mode for String Data with Grouping

A wish along this line:
:folded_hands: Summary and Tabulate: add aggregation option for Character columns 

Once the feature has been implemented, you will be able to use the Tables/Summary function for this task.

Recommended Articles