Hi,
What is the best way to set row values for a given column as a character sequence?
This is easily done when creating a new column (Data Type == Character) by: Column Info --> Initialize Data --> Sequence Data --> "a", "b", "c", etc.
What is the best way to script this?
I am using JMP10.
Thanks!
Clever workaround!
Here's another way I've used that may be more general and not requiring a formula (but there "should" be a simpler way..):
dt = Open( "$SAMPLE_DATA/Big Class.JMP" );
labels = {"a", "b", "c"}; // could be any sequence
dt << New Column( "Char Sequence2",
Character,
Nominal,
Values(
Insert(
Repeat( labels, N Rows( dt ) / N Items( labels ) ),
If( Mod( N Rows( dt ), N Items( labels ) ),
labels[1 :: Mod( N Rows( dt ), N Items( labels ) )],
{}
)
)
)
);
I found one simple workaround. Set values using Sequence and then change these values to the desired character string using Value Labels.
/*
bigClass = Open( "$SAMPLE_DATA/Big Class.JMP" );
bigClass << New Column( "Char Sequence",
Character,
Nominal,
Format( "Best", 9 ),
Formula( Sequence( 1, 3, 1, 1 ) ),
Value Labels( {1 = "a", 2 = "b", 3 = "c"} ),
Use Value Labels( 1 )
);
*/
Clever workaround!
Here's another way I've used that may be more general and not requiring a formula (but there "should" be a simpler way..):
dt = Open( "$SAMPLE_DATA/Big Class.JMP" );
labels = {"a", "b", "c"}; // could be any sequence
dt << New Column( "Char Sequence2",
Character,
Nominal,
Values(
Insert(
Repeat( labels, N Rows( dt ) / N Items( labels ) ),
If( Mod( N Rows( dt ), N Items( labels ) ),
labels[1 :: Mod( N Rows( dt ), N Items( labels ) )],
{}
)
)
)
);
Thanks MS.
Yes, it seems there is no simple answer for this one.
Facing this problem myself today I found this post. It did give me a few logic ideas. Below is a slightly more condensed technique.
dt = Open( "$SAMPLE_DATA/Big Class.JMP" ); labels = {"a", "b", "c"}; // could be any sequence dt << New Column( "Char Sequence2", Character, Nominal, Set Each Value(labels[1 + Mod( Row() - 1, n items(labels) )]) );
Indeed I had hoped for sequence to function on character as well. But at least leveraging set each value you can simplify the flow.