범주 수준 요약다른 항목을 "기준" 그룹으로 사용하여 열 값에 대한 요약을 얻고 싶습니다.이는 Summary()가 N 카테고리에서 수행하는 것과 비슷하지만 실제 값의 수가 아니라 실제 값의 목록을 원합니다.예를 들어 다음 표를 가져옵니다.

나는 다음과 같은 것을 원한다:

Summary()에서 하위 그룹으로 'Category'를 사용한 다음 Recode 및 Combine Columns()를 사용하여 무언가를 할 수 있다고 생각하고 있습니까?더 좋고 더 영리한 아이디어가 있습니까?나는 커뮤니티를 조금 샅샅이 뒤졌지만 비슷한 것을 찾을 수 없었습니다 (놀랍게도?). 아마도 연관 배열을 사용할 장소일까요?이 예제 테이블은 작습니다. 이 테이블을 실행할 테이블은 그룹 열에 대해 수백 개의 "수준"이 있는 수백만 행이 될 수 있습니다.
Re: 범주별 수준 요약향후 독자가 문제를 해결하는 다양한 방법을 볼 수 있도록 정답을 제공한 모든 응답을 솔루션으로 표시하는 것이 적절할 것입니다.Re: 범주별 수준 요약솔루션에 대한 두 가지 덕분에 결국 연관 배열로 작업을 수행했습니다.이 세 가지 접근 방식 중 하나가 이 작업을 시도하는 다음 사람에게 효과가 있기를 바라며 여기에서 해당 내용을 덤프합니다.
Names Default To Here( 1 );
// Create the beginning table
dt = New Table( "Example",
Add Rows( 11 ),
New Column( "Group",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8] )
),
New Column( "Category",
Character,
"Nominal",
Set Values( {"A", "A", "B", "A", "D", "X", "Y", "Z", "A", "B", "C"} )
)
);
// let Summary do N Categories() for us
dt_sum = dt << Summary( Group( :Group ), N Categories( Category ) );
// the name of the column for which we want a list of the categories
category_col = "Category";
sum_colname = "Value List("|| category_col || ")";
// new col in the summary table to hold the list of values
dt_sum << New Column(sum_colname, Character);
// dump the group col into a matrix for quicker access
sum_groupdat = dt_sum:Group << Get As Matrix();
main_groupdat = dt:Group << Get As Matrix();
For( ri = 1, ri <= N Rows( dt_sum ), ri++,
// rows in main table that match the 'group by' col
inds = Loc( main_groupdat, sum_groupdat[ri] );
tmpaa = Associative Array( Column( dt, category_col )[inds] );
keys = tmpaa << Get Keys();
// if the category_col is numeric, need to convert the numbers to chars!
If( Is Number( keys[1] ),
charkeys = {};
For( ki = 1, ki <= N Items( keys ), ki++,
charkeys[ki] = Char( keys[ki] );
);
,
charkeys = keys
);<BR /> // stuff all the items together and dump it into this row
valstr = Concat Items( charkeys, "," );
Column( dt_sum, sum_colname )[ri] = valstr;
);
Re: 범주별 수준 요약이제 Jim이 이미 해결책을 제시한 것을 알 수 있습니다.
다음은 전체 데이터 세트에서도 잘 작동하는 Tabulate and Combine Columns(Multiple Response Column)를 사용하는 다른 접근 방식입니다.
// Groups is the example table with 2 nominal columns
DT_GroupCategory = Data Table( "Groups" );
// creates a cross table
Tab_DT_GroupCategory = DT_GroupCategory << Tabulate(
Add Table(
Column Table( Grouping Columns( :Category ) ),
Row Table( Grouping Columns( :Group ) )
)
);
// make data table from it
DT_GroupCategory_CrossTab = Tab_DT_GroupCategory << Make Into Data Table;
DT_GroupCategory_CrossTab << Add Multiple Columns( "N Categories", 1, after( 1 ), Numeric );
Names_DT_GroupCategory_CrossTab = DT_GroupCategory_CrossTab << Get Column Names;
// replace 0 by missing and everything else by column name (probably not the most efficient way to do this)
For( i=3, i<=N Items( Names_DT_GroupCategory_CrossTab ), i++,
Column( DT_GroupCategory_CrossTab, i ) << Data Type( "Character" );
For( j=1, j<=N Rows( DT_GroupCategory_CrossTab ), j++,
If( Column( DT_GroupCategory_CrossTab, i )[j] == "0",
Column( DT_GroupCategory_CrossTab, i )[j] = "",
Column( DT_GroupCategory_CrossTab, i )[j] = Char( Names_DT_GroupCategory_CrossTab[i] );
)
)
);
// make multiple response column with Cols -> Utilities -> Combine Columns
DT_GroupCategory_CrossTab << Combine Columns(
delimiter( "," ),
Columns( 2::N Items( Names_DT_GroupCategory_CrossTab ) ),
Selected Columns are Indicator Columns( 0 ),
Column Name( "Values(Category)" )
);
// add formula to get N Categories. +1 is added for one less comma, then div by 2 to get number of categories
Column( DT_GroupCategory_CrossTab, "N Categories" ) << Formula( (Length( :Name( "Values(Category)" ) ) + 1) / 2 );
Tab_DT_GroupCategory << Close Window;

Re: 범주별 수준 요약시작하는 방법은 데이터 테이블에서 분할을 수행한 다음 거기에서 작업하는 것입니다.다음은 원하는 결과를 얻기 위해 작성한 간단한 스크립트입니다.이 작업을 대화식으로 수행해야 하는 경우 스크립트의 단계를 따르십시오.
Names Default To Here( 1 );
// Create the beginning table
dt = New Table( "Example",
Add Rows( 11 ),
New Column( "Group",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8] )
),
New Column( "Category",
Character,
"Nominal",
Set Values( {"A", "A", "B", "A", "D", "X", "Y", "Z", "A", "B", "C"} )
)
);
// Change the group column to character so
// split columns are blanks and not missing values
dt:Group << data type( character );
// Split the columns
dtSplit = dt << Split( Split By( :Category ), Split( :Group ), Group( :Group ), Sort by Column Property );
// Change the data type back
dt:Group << data type( numeric );
dtSplit:Group << data type( numeric );
// Convert all of the non blank entries to the value of the column name
For( i = 2, i <= N Cols( dtSplit ), i++,
theRows = dtSplit << get rows where( As Column( dtsplit, i ) != "" );
If( N Rows( theRows ) > 0,
Column( dtSplit, i )[theRows] = Column( dtsplit, i ) << get name
);
);
// get all of the character column names
namesList = dtSplit << get column names( character, string );
// Create the combined column
dtSplit << Combine Columns(
delimiter( "," ),
Columns( :a, :b, :c, :d, :X, :y, :z ),
Column Name( "Values (Category)" )
);
// Count the number of combined values
dtSplit << New Column( "N Categories (Category)",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
count = 1;
While( Word( count, :Name( "Values (Category)" ), "," ) != "", count++ );
count = count - 1;
)
);
// get rid of the formula
dtSplit:Name("N Categories (Category)") << delete property(formula);
// delete the unnecessary columns
dtSplit << delete columns( namesList );