使用循環重新編碼一系列列你好,
我經常收到多個打孔數據“爆炸”成單獨的列,其中選項1 = 1,選項2 = 2等的肯定響應。我必須將這些重新編碼為二進製文件,我想在可重現的腳本中使用它。我認為我在使用以下腳本的正確軌道上,但是當我運行它時,我在訪問或評估'下標'時遇到錯誤“對像不可訂閱{1}。我附上了一個樣本數據集。提前致謝。
dt = Current Data Table();
lstColNames = {"14_1","14_2","14_3","14_4","14_5","14_6","14_7","14_8","14_9","14_10","14_11","14_12","14_13"};
For Each Row( For( i = 1, i <= N Items( lstColNames ), i++, If( lstColNames[i][]== i, lstColNames[i][] = 1 ) ) );
Re:用循環重新編碼一系列列謝謝!我能夠使用它為我的項目創建一個可重現的腳本。我很感激你的幫助!
Re:用循環重新編碼一系列列For( i = 1, i <= 13, i++,
只需減少For()循環
Re:用循環重新編碼一系列列謝謝,TX,適用於我發布的樣本。當它們位於包含更多列的更大數據集中時,如何將此限制僅限於列14_1到14_13?這就是我試圖使用特定列表的原因。
Re:用循環重新編碼一系列列看看這是不是你想要的
Names Default To Here( 1 );
dt = Current Data Table();
lstColNames = dt << get column names( string, nominal );
For( i = 1, i <= N Items( lstColNames ), i++,
theRows = dt << get rows where( As Column( dt, lstColNames[i] ) >= 1 );
If( N Rows( theRows ) > 0,
Column( dt, lstColNames[i] )[theRows] = 1
);
theRows = dt << get rows where( Is Missing( As Column( dt, lstColNames[i] ) ) == 1 );
If( N Rows( theRows ) > 0,
Column( dt, lstColNames[i] )[theRows] = 0
);
Column( dt, lstColNames[i] ) << delete property( "Value Labels" );