Subscribe Bookmark RSS Feed

enter value in specific cell

KinKame

Community Trekker

Joined:

Nov 30, 2015

Hello,

new little problem.

I would like to enter a value in a specific cell by

1) row name

2) column name

for example

I would like to enter value 25 in cell

     row (from col1) = 4

     col = SYN

Col1SYNMIS
110

2

15
320
4
5
6
7
8

best regards

Lionel

1 ACCEPTED SOLUTION

Accepted Solutions
robot

Community Trekker

Joined:

Feb 27, 2012

Solution

Hi llupo0,

What are you trying to accomplish with your script?  I think this may be closer to what you are trying to do.

dt = New Table( "Little Class",

       Add Rows( 3 ),

       New Column( "name", Character, "Nominal", Set Values( {"KATIE", "LOUISE", "JANE"} ) ),

       New Column( "height", "Continuous", Set Values( [59, 61, 55] ) ),

       New Column( "weight", "Continuous", Set Values( [100, 150, 200] ) )

);

column_name = dt << get column names();

my_list = {62, 151};

For( i = 2, i <= N Items( column_name ), i++, // Add < sign.

       r = dt << Get Rows Where( :name == "LOUISE" );

       Column( i )[r] = my_list[i - 1]; // my_list has only two values, thus index [i - 1] is used for i = 3.

);

7 REPLIES
robot

Community Trekker

Joined:

Feb 27, 2012

Hi llupo0,

Try this:

// Create example table.

dt = New Table( "Little Class",

       Add Rows( 3 ),

       New Column( "name", Character, "Nominal", Set Values( {"KATIE", "LOUISE", "JANE"} ) ),

       New Column( "height", "Continuous", Set Values( [59, 61, 55] ) )

);

// Update value from row number.

dt:height[2] = 62;

// Update value from column value.

r = dt << Get Rows Where( :name == "LOUISE" );

dt:height[r] = 63;

KinKame

Community Trekker

Joined:

Nov 30, 2015

Morning Robot

thank you for your feedback.

I see how you addressed the row. So in the same way I can also with a for loop have column movement.

tried but doesnt work :-(

dt = New Table( "Little Class",

       Add Rows( 3 ),

       New Column( "name", Character, "Nominal", Set Values( {"KATIE", "LOUISE", "JANE"} ) ),

       New Column( "height", "Continuous", Set Values( [59, 61, 55] ) ),

       New Column( "weight", "Continuous", Set Values( [100, 150, 200] ) ),

);

column_name = dt << get column names();

//my_list = {10, 20};

my_list = 777;

for(i=2, i=3, i++,

  r = dt << Get Rows Where( :name == "LOUISE" );

  dt:column_name= my_list

);

robot

Community Trekker

Joined:

Feb 27, 2012

Solution

Hi llupo0,

What are you trying to accomplish with your script?  I think this may be closer to what you are trying to do.

dt = New Table( "Little Class",

       Add Rows( 3 ),

       New Column( "name", Character, "Nominal", Set Values( {"KATIE", "LOUISE", "JANE"} ) ),

       New Column( "height", "Continuous", Set Values( [59, 61, 55] ) ),

       New Column( "weight", "Continuous", Set Values( [100, 150, 200] ) )

);

column_name = dt << get column names();

my_list = {62, 151};

For( i = 2, i <= N Items( column_name ), i++, // Add < sign.

       r = dt << Get Rows Where( :name == "LOUISE" );

       Column( i )[r] = my_list[i - 1]; // my_list has only two values, thus index [i - 1] is used for i = 3.

);

KinKame

Community Trekker

Joined:

Nov 30, 2015

trying to fill in value for certain column by row where row represents working weeks

so kind of weekly update record table.

ok it works! thank you. Also it is a good learning for me on how to manipulate table and data :-)

BTW,

how do you do to copy JSL code keeping color just like in JMP?

pmroz

Super User

Joined:

Jun 23, 2011

>> BTW,

>> how do you do to copy JSL code keeping color just like in JMP?

Copy/paste the code from the JSL script editor into MS-Word.

Copy/paste the code from MS-Word to this forum.

// JSL Script

a = {"Hello", "World"};

msharp

Super User

Joined:

Jul 28, 2015

It doesn't have to be word.  Any text editor that supports formatting, for example, I often copy and paste it into an email message since I always have Outlook open, but rarely have Word open.

Also here is how you would get your code working: (Just an example in debugging)

First, i=3 isn't a Boolean, if you meant i==3, this would never evaluate to true since i=2.  So I made the assumption you meant i<=3.

Next, you change my_list from a list to a number, so you need to reflect that in the for loop.  my_list becomes my_list.

Lastly, you need to be aware of the order of operations.  dt:column_name  This will first query the dt namespace to find a variable column_name.  It just so happens that there is indeed a column named name.  So then the will find the row in the column name, thus dt:column_name[1] == "KATIE", dt:column_name[2] == "LOUISE", ect.  However, your script will then die since "KATIE" is not a list or matrix, and there are no subscripts so kills it.  To keep order of operations correct you could simply change the code to below.  Alternatively you could use the column function to remove ambiguity.  Column(dt, i), or Column(dt, column_name) (which happen to be the same in this case since your column_name list is every column in the data table.)

column_name = dt << get column names();

//my_list = {10, 20};

my_list = 555;

for(i=2, i<=3, i++,

  r = dt << Get Rows Where( :name == "LOUISE" );

  dt:(column_name[i])[r] = my_list;

);

KinKame

Community Trekker

Joined:

Nov 30, 2015

thank you very for your time explaining me my mistakes.

Learning from it