cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
sophiaw
Level III

Selecting Multiple Rows and Imputing a Value in a Column

Hi,

I have a data table where I created an empty column, and I wanted to input values into that column based on the rows selected. I have a list of search parameters, and I can select which rows I want based on the list I input, but I just want to put the value of the list into the empty column for all the selected rows. I have most of the script working, but I just can't get the last part which is actually inputting the value into the new column for all the selected rows. Any suggestions?

group_gender = {"Male","Female"};

results << New Column("Gender", Character, Nominal);


For(i = 1, i < nitems(group_gender), i++,

     results << Select Where(Contains(:Names,group_gender));

     selRows = results << getSelectedRows;

     Column(results, Gender[selRows]) = eval(group_gender);

);

When I run this, I get an error "attempting to assign to an object that is not an L-value". Is there a way I can just change a column for all the selected rows to some value?

1 ACCEPTED SOLUTION

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

Re: Selecting Multiple Rows and Imputing a Value in a Column

Use AsColumn(dt,col) for assignment and place the index outside the parentheses.

For( i = 1, i <= NItems( group_gender ), i++,

    results << Select Where( Contains( :Names, group_gender[i] ) );

    selRows = results << getSelectedRows;

    AsColumn( results, "Gender" )[selRows] = group_gender[i];

    // this works to:

    // results:Gender[selRows] = group_gender;

);

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Selecting Multiple Rows and Imputing a Value in a Column

Use AsColumn(dt,col) for assignment and place the index outside the parentheses.

For( i = 1, i <= NItems( group_gender ), i++,

    results << Select Where( Contains( :Names, group_gender[i] ) );

    selRows = results << getSelectedRows;

    AsColumn( results, "Gender" )[selRows] = group_gender[i];

    // this works to:

    // results:Gender[selRows] = group_gender;

);

sophiaw
Level III

Re: Selecting Multiple Rows and Imputing a Value in a Column

Thank you MS! I knew that last line had to be wrong, and that fixed it!