I know... but it is a surprisingly good method from a time standpoint. Interestingly the concat method, as odd as it is, is really fast as well.
For example, for a 200,000 row x 10 column table (compressed file attached) of these values, here are the runtimes:
Names Default To Here( 1 );
dt = Current Data Table();
t1 = HP Time();
dt << new column("xx",
formula(sum( design (dt[row(), {:col1, :col2, :col3, :col4, :col5, :col6, :col7, :col8, :col9, :col10}], {"test"})))
);
t2 = hptime();
dt << New Column( "xx",
formula(
count = 0;
dt = :Col1 << get data table;
For( i = 1, i <= 10, i++,
If( Column( dt, i )[Row()] == "test", count ++)
);
count;
)
);
t3 = hptime();
dt << new column("xx", formula(nrow(loc(dt[row(), {:col1, :col2, :col3, :col4, :col5, :col6, :col7, :col8, :col9, :col10}], "test"))));
t4 = hptime();
dt << new column("concat", character, formula(Col1 || :Col2 || :Col3 || :Col4 || :Col5 || :Col6 || :Col7 || :Col8 || :Col9 ||:Col10));
dt << new column("xx", formula(length(:concat)-30));
t5 = hptime();
print(evalinsert("Design matrix method: ^(t2-t1)/1e6^ seconds."));
print(evalinsert("Looping method: ^(t3-t2)/1e6^ seconds."));
print(evalinsert("Nrow(Loc()) method: ^(t4-t3)/1e6^ seconds."));
print(evalinsert("Concat method: ^(t5-t4)/1e6^ seconds."));