I want to check values in two numeric columns within a data table. Now I have these two numeric columns' names in a list. I use a for loop to iterate through the list of these chosen numeric column names, then i want to check against a threshold value (say 100). Then I want to create a new column and put labels accordingly - either label "A" or "B" - depending on the given columns in the data table.
Let's say these are the two numeric columns:
numeric_col_1 = {100, 200, 250, 700}
numeric_col_2 = {200, 250, 500, 100}
And the threshold is 100.
Now the labeled columns pseudocode I want to implement is as follows:
labeled_col = (if numeric_col > 100, "A", "B");
So the labeled columns will now show:
labeled_col_1 = {"B", "A", "A", "A"};
labeled_col_2 = {"A", "A", "A", "B"};
Here is some example code:
concat_dt = datatable("concatenated");
new_val_list = {"num_col1", "num_col2"};
name_list = {"col1", "col2"};
stop = nitems(new_val_list);
for (i = 1, i <=stop, i++,
col_name = name_list[i] || "_Label_A_B";
show(col_name);
concat_dt << New Column( col_name,
Character,
"Nominal",
Formula( If( Column(concat_dt, new_val_list[i]) > 200, "A", "B" ) )
)
);
But the above code only shows empty columns even though they have been created with their respective column names in the data table.