Change column data type with special namesI like to write a script to get the column names that starts with "WIFI" and "BR" and then change the modeling type as "Continuous"). Something like belwo
Current data Table();
col_list = dt << get column names( "WIFI","BR" );
col_list << Set Modeling Type("Continuous");
Can you help me ? Thanks
Re: Change column data type with special namesI don't think the response you selected as "The Solution" is the solution.
Re: Change column data type with special namesThanks so much. It works fine.
Re: Change column data type with special namesGood catch @txnelson. Given any more than a simple match I default to regex. Thus I present yet another option:
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: Change column data type with special namesI am taking a small amount of liberty with @ih JSL. Since you specified, that you are looking for column names that "begin" with specific string values, I would insure this by specifying that the Contains return value has to be a 1, indicating the value was found in column 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" );
)
);
You may also choose the following methodology, which I find to actually be more readable
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: Change column data type with special namesMaybe something like this?
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" );
)
);