Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted

## Get Selected Rows results in error, when using the rows

Hey,

i can´t figure out, why the following results in an error:

``````For( i = 1, i <= N Items(list), i++,
item = list[i];
rows = dt << Get Rows Where(
dt:foo == item
);
Column(dt, "bar" )[rows] = "foobar";
);``````

The error is:

"Cannot set value for the column 'bar' because the row number (-1) is not valid.{941}"

Can anyone enlighten me?

Thank you!

5 REPLIES 5
Highlighted

## Re: Get Selected Rows results in error, when using the rows

Here is your script, running with some example data that does not have an issue when running JMP 12 or JMP 14.  What I would check on your data is that column "bar" is defined as a character column.

``````names default to here(1);
dt=New Table( "Example",
New Column( "foo", Character, "Nominal", Set Values( {"a", "", "a"} ) ),
New Column( "bar", Character, "Nominal", Set Values( {"", "", ""} ) )
);
list = {"a","b"};

For( i = 1, i <= N Items(list), i++,
item = list[i];
rows = dt << Get Rows Where(
dt:foo == item
);
Column(dt, "bar" )[rows] = "foobar";
);``````
Jim
Highlighted

## Re: Get Selected Rows results in error, when using the rows

Thanks for the quick anwser!

The column is correctly defined and i tried many variants now. Converting the matrix to a list and iterating it etc. --> doesn´t work.

I know that it should work fine. I actually use "<< Get Rows Where" in the same script and it works.

However, I now switched to the good old For Each Row loop to do the trick, no problem here.

Highlighted

## Re: Get Selected Rows results in error, when using the rows

Is your 'dt' table derived from another table?  I think it may be trying to map a row number from one table to another, but it's hard to say for sure without knowing more about the data.

Highlighted

## Re: Get Selected Rows results in error, when using the rows

Your guess is kind of correct. "dt" is actually the original data table. From there i derive other tables and then identify the items i want to select.

Nowing the items, I return to "dt" and perform "<< Get Rows Where (items i want to get)" to get the row numbers. Then i like to set "dt:colum[rows i got] = ...".

Sorry that i neither can´t explain it better or provide the data.

Highlighted

## Re: Get Selected Rows results in error, when using the rows

I think this error can come about due to the current data table.  The script below will error, but if you comment out the Current Data Table(dt) line, it works as expected.  I'm not sure why this works this way - we will look into it further to see if changes are possible to avoid the need to change the Current Data Table().

``````dt=Open("\$SAMPLE_DATA/Big Class.jmp");
dt<<Select Where(:sex == "M");
dtm = dt<<Subset(Selected Rows, Link To Original Data Table(1));
// Current Data Table(dt);
rows = dt << Get Rows Where(:age == 15);
Column(dt, "name")[rows] = "foobar";``````
Article Labels

There are no labels assigned to this post.