Subscribe Bookmark RSS Feed

combining 'set each value' and 'if'

arnow

Community Trekker

Joined:

Feb 6, 2012

Hello,

I have a problem using 'if' in the evaluation of 'set each value'. In the data table (dt_optics) are numeric continuous columns containing counts of a control. Now, I need to check for nonzero counts and store the result in new columns (to later perform logistic regression). The code I am using is:

column_list = dt_optics << get column names;

n_columns = N Col( dt_optics );

For( i = 3, i <= n_columns, i++,

      column_name = Char( Column Name( i ) ) || "_bin";

      dt_optics << New Column( column_name,

            continuous,

            ordinal,

            set each value( If( (Column( dt_optics, column_list[i] )) == 0, 0, 1 ) )

      );

);

In the column I create all values are 1, no matter what the value in the initial column was (I am sure that there are nonzeros in the initial column). Can somebody help me with that?

Thanks a lot,

Arno

1 ACCEPTED SOLUTION

Accepted Solutions
ms

Super User

Joined:

Jun 23, 2011

Solution

You need to append square brackets to the column within SetEachValue() to involve the column values rather than the column object.

This should work (only change is the [ ])

For( i = 3, i <= n_columns, i++,

      column_name = Char( Column Name( i ) ) || "_bin";

      dt_optics << New Column( column_name,

            continuous,

            ordinal,

            set each value( If( Column( dt_optics, column_list[i] )[] == 0, 0, 1 ) )

      );

);

1 REPLY
ms

Super User

Joined:

Jun 23, 2011

Solution

You need to append square brackets to the column within SetEachValue() to involve the column values rather than the column object.

This should work (only change is the [ ])

For( i = 3, i <= n_columns, i++,

      column_name = Char( Column Name( i ) ) || "_bin";

      dt_optics << New Column( column_name,

            continuous,

            ordinal,

            set each value( If( Column( dt_optics, column_list[i] )[] == 0, 0, 1 ) )

      );

);