안녕하세요,
특정 값을 포함하는 모든 열을 해당 행에 나열하고 해당 열의 목록을 얻고 싶습니다.
목록의 모든 문자 열을 나열하는 것으로 시작하고 루프를 반복하여 각 열에 특정 값이 포함되어 있는지 확인합니다. 다음은 내가 사용한 코드입니다. 어떻게 도와드릴까요? 미리 감사합니다
col = dt << get column names( character );
nc = N Items( col );
colList = {};
For( i = 1, i <= nc, i++,
If(Contains (as column(dt,col[i]) ,"null"),
Insert Into( colList, col[i] ))
);<BR />
나는 이것이 당신이 원하는 것을 할 수 있다고 생각합니다
Names Default To Here( 1 );
dt = current data table();
col = dt << get column names( character );
nc = N Items( col );
colList = {};
For( i = 1, i <= nc, i++,
If( N Rows( dt << get rows where( As Column( dt, col[i] ) == "null" ) ) > 0,
Insert Into( colList, col[i] )
)
);아래에 몇 가지 더 많은 방법이 있습니다. 이해하기 쉽기 때문에 txnelson의 솔루션을 사용하는 것이 좋습니다.
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(5),
New Column("Column 1", Character, "Nominal", Set Values({"null", "a", "s", "d", "vb"})),
New Column("Column 2", Character, "Nominal", Set Values({"a", "a", "a", "a", "a"})),
New Column("Column 3", Character, "Nominal", Set Values({"a", "a", "a", "a", "a"})),
New Column("Column 4", Character, "Nominal", Set Values({"null", "a", "a", "a", "a"})),
New Column("Column 5", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4, 5])),
New Column("Column 6", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4, 5])),
New Column("Column 7", Character, "Nominal", Set Values({"a", "a", "a", "null", "a"}))
);
//using Loc and matrix subscripting
char_col_names = dt << Get Column Names(character);
null_cols = {};
For(i = 1, i <= N Items(char_col_names), i++,
If(N Items(Loc(dt[0, char(char_col_names[i])], "null")) > 0,
Insert Into(null_cols, char_col_names[i]);
);
);
Show(null_cols);
//Using list flattening and loc with "2d" matrix
//List flattening function from here https://community.jmp.com/t5/Discussions/JSL-Question-How-to-flatten-quot-a-list-of-lists/td-p/56535
rec = Function({ll},
{i},
If(Is List(ll),
For(i = 1, i <= N Items(ll), i++,
If(!Is List(ll[i]),
Insert Into(llnew, ll[i]), //else
rec(ll[i])
)
)
)
);
flatten = Function({ulist},
{llnew = {}},
rec(ulist);
llnew;
);
col_names = dt << Get Column Names();
//https://community.jmp.com/t5/JSL-Cookbook/Using-Loc-with-a-2D-Matrix/ta-p/195207
null_loc = Loc(flatten(dt[0, col_names ]), "null") - 1;
column_loc = Mod(null_loc, N Items(col_names )) + 1;
Show(col_names[column_loc]);스크립트 속도로 "문제"가 발생하면 이 항목이 도움이 될 수 있는지 확인할 수 있습니다. 데이터 테이블을 반복하거나 Recode를 사용하거나 Get을 사용해야 합니다.