Subscribe Bookmark RSS Feed

Selecting Multiple Rows and Imputing a Value in a Column

sophiaw

Community Trekker

Joined:

Jul 10, 2015

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
Solution

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;

);

2 REPLIES
Solution

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

Community Trekker

Joined:

Jul 10, 2015

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