通过将引用从使用:Name()函数更改为使用Column()和As Column()函数,我对脚本进行了一些修改。 我还稍微更改了<< <<获得列名称的调用。 但是除此之外,您走在正确的道路上。 我的脚本似乎可以按需工作
Names Default To Here( 1 );
dt = Current Data Table();
col = dt << get column names( string, continuous );
nc = N Items( col );
For( i = 1, i <= nc, i++,
mu = Col Mean( Column( col[i] ) );
sd = Col Std Dev( Column( col[i] ) );
lo = mu - 3 * sd;
hi = mu + 3 * sd;
rows = dt << Get Rows Where( lo <= as Column( col[i] ) <= hi );
Column( col[i] ) << Color Cells( "Red", rows );
rows = dt << Get Rows Where( as Column( col[i] ) < lo | as Column( col[i] ) > hi );
Column( col[i] ) << Color Cells( "Purple", rows );
lo = mu - 2 * sd;
hi = mu + 2 * sd;
rows = dt << Get Rows Where( lo <= as Column( col[i] ) <= hi );
Column( col[i] ) << Color Cells( "Yellow", rows );
lo = mu - sd;
hi = mu + sd;
rows = dt << Get Rows Where( lo <= as Column( col[i] ) <= hi );
Column( col[i] ) << Color Cells( "Green", rows );
);
我最初的目标是根据某个单元格的值是否在以下范围内对单元格进行着色:1 sigma,> 1 sigma但<2 sigma,> 2 sigma但<3 sigma和> 3 sigma是该列的标准偏差。现在,我希望遍历所有列并对所有列执行条件着色,但是如下所示的for循环代码不起作用。
col = dt <<获取列名(字符串); nc = nitems(col); for(i = 2,i <= nc,i ++,mu = Col Mean(:Name(col [i]))); sd = Col Std Dev(:Name(col [i])); lo = mu -3 * sd; hi = mu + 3 * sd; rows = dt <<获取行,其中(lo <=:Name(col [i])<= hi);:Name(col [i])<<颜色单元格(“红色“,行);行= dt <<获取行,其中(:Name(col [i]) hi);:Name(col [i])<<颜色单元格( “紫色”,行); lo = mu-2 * sd; hi = mu + 2 * sd;行= dt <<获取行其中(lo <=:Name(col [i])<= hi);:Name (col [i])<<彩色单元格(“黄色”,行); lo = mu-sd; hi = mu + sd; rows = dt <<获取行,其中(lo <=:Name(col [i]) <= hi);:Name(col [i])<<彩色单元格(“绿色”,行););