使用關聯數組重命名列嗨,我正在嘗試使用關聯數組重命名一堆列。 我一直以大類數據為例。 我將不勝感激一些修復我的腳本的幫助。
Names Default To Here( 1 );
dt = Data Table ("Big Class.jmp");
//Use and array to rename the Big Class table columns to "spanish"
newColNames = Associative Array();
newColNames["name"] = "nombre";
newColNames["age"] = "edad";
newColNames["sex"] = "sexo";
newColNames["height"] = "altura";
newColNames["weight"] = "peso";
uno = newColNames << Get Keys(); //for testing
newN = newColNames << Get Values({"name"}); //for testing
oriNames = dt << Get Column Names(); // in case there are variation on the number/name of columns
For( i=1, 1 <= N Items(oriNames), i++,
key = oriNames[i];
Column(dt, key ) << set name (newColNames<<GET values=""></GET>數據表腳本回复:使用關聯數組重命名列@ian_jmp
非常感謝你的幫助。 重要課程:檢查你的 i's 和“獲取值”和“獲取值”。
此致,
阿爾
回复:使用關聯數組重命名列@ian_jmp我花了太長時間才看到“1”!
dt = Open( "$sample_data/Big Class.jmp" );
//Use and array to rename the Big Class table columns to "spanish"
newColNames = Associative Array();
newColNames["name"] = "nombre";
newColNames["age"] = "edad";
newColNames["sex"] = "sexo";
newColNames["height"] = "altura";
newColNames["weight"] = "peso";
uno = newColNames << Get Keys(); //for testing
newN = newColNames << Get Values( {"age"} ); //for testing
oriNames = dt << Get Column Names( "string" ); // in case there are variation on the number/name of columns
For( i = 1, i <= N Items( oriNames ), i++,
key = oriNames[i];
Column( dt, key ) << set name( newColNames[key] );
);回复:使用關聯數組重命名列你非常接近:
Names Default To Here( 1 );
dt = Open("$SAMPLE_DATA/Big Class.jmp");
//Use and array to rename the Big Class table columns to "spanish"
newColNames = Associative Array();
newColNames["name"] = "nombre";
newColNames["age"] = "edad";
newColNames["sex"] = "sexo";
newColNames["height"] = "altura";
newColNames["weight"] = "peso";
oriNames = dt << Get Column Names("String"); // in case there are variation on the number/name of columns
For( i=1, i <= N Items(oriNames), i++,
key = oriNames[i];
Column(dt, key ) << set name ( newColNames << Get Value (key) );
);