使用特殊名称更改列数据类型我喜欢编写一个脚本来获取以“WIFI”和“BR”开头的列名,然后将建模类型更改为“连续”)。像贝尔沃这样的东西
当前数据表 ();
col_list = dt << 获取列名称 ( “无线上网” , “BR” );
col_list << 设置建模类型 ( “连续” );
你能帮助我吗 ?谢谢
Re:使用特殊名称更改列数据类型我不认为您选择的“解决方案”的响应是解决方案。
Re:使用特殊名称更改列数据类型非常感谢。它工作正常。
Re:使用特殊名称更改列数据类型接得好 @txnelson 。 除了简单的匹配,我默认使用正则表达式。 因此,我提出了另一种选择:
dt = Open( "$Sample_data/iris.jmp" );
cols = dt << Get column Names();
for( i = 1, i <= N Items( cols ), i++,
if( !Is missing(Regex( char( cols[i] ) , "^(sepal|width)(.*)", "\0", IGNORECASE) ),
Column( dt, cols[i] ) << Set Modeling Type( "Nominal" );
)
);
Re:使用特殊名称更改列数据类型我带着少量的自由 @ih JSL。 既然你指定了,你正在寻找具有特定字符串值“开始”的列名,我会通过指定Contains返回值必须为1来确保这一点,表明在第1列中找到了值。
dt = Open( "$Sample_data/iris.jmp" );
cols = dt << Get column Names();
for( i = 1, i <= N Items( cols ), i++,
if( contains( uppercase( cols[i] ), "SEPAL" ) ==1 |
contains( uppercase( cols[i] ), "WIDTH" ) == 1
,
Column( dt, cols[i] ) << Set Modeling Type( "Nominal" );
)
);
您也可以选择以下方法,我发现它实际上更具可读性
Names Default to Here( 1 );
dt = Open( "$Sample_data/iris.jmp" );
cols = dt << Get column Names();
for( i = 1, i <= N Items( cols ), i++,
if( Left( uppercase( cols[i] ), 5 ) == "SEPAL" |
Left( uppercase( cols[i] ), 5 ) == "WIDTH"
,
Column( dt, cols[i] ) << Set Modeling Type( "Nominal" );
)
);
Re:使用特殊名称更改列数据类型也许是这样的?
Names default to here ( 1 );
dt = Open( "$Sample_data/iris.jmp" );
cols = dt << Get column Names();
for( i = 1, i <= N Items( cols ), i++,
if( contains( uppercase( cols[i] ), "SEPAL" ) |
contains( uppercase( cols[i] ), "WIDTH" )
,
Column( dt, cols[i] ) << Set Modeling Type( "Nominal" );
)
);