cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
robot
Level VI

Set Row Values as Character Sequence

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Set Row Values as Character Sequence

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 ) )],

                             {}

                      )

              )

       )

);

View solution in original post

4 REPLIES 4
robot
Level VI

Re: Set Row Values as Character Sequence

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 )

);

*/

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Set Row Values as Character Sequence

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 ) )],

                             {}

                      )

              )

       )

);

robot
Level VI

Re: Set Row Values as Character Sequence

Thanks MS.

Yes, it seems there is no simple answer for this one.

Nate_Riordan
Staff (Retired)

Re: Set Row Values as Character Sequence

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.