Subscribe Bookmark RSS Feed

Set Row Values as Character Sequence

robot

Community Trekker

Joined:

Feb 27, 2012

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
Solution

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

                             {}

                      )

              )

       )

);

4 REPLIES
robot

Community Trekker

Joined:

Feb 27, 2012

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 )

);

*/

Solution

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

Community Trekker

Joined:

Feb 27, 2012

Thanks MS.

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

Nate_Riordan

Staff

Joined:

Sep 10, 2015

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.