combining 'set each value' and 'if'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />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
combining 'set each value' and 'if'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 ) )
);
);