在循环中如何指示其他列[I]你好。
我必须再次寻求帮助。我编写了一个脚本来计算数字列和下一个值之间的变化百分比。不幸的是我收到一个错误:“1897_Canvi列中断
无法将参数转换为数字[或矩阵] 1次在行:{1}操作:减去,numericColNames [X] - numericColNames [i]
公式评估错误已被忽略“
这是numericColNamesn:
{“_ 1842 _”,“_ 1877_”,“_ 1887 _”,“_ 1897_”,“_ 1900 _”,“_ 1910_”,“_ 1920_”,“_ 1930_”,“_ 1940 _”,“_ 1950_”,“_ 1960_”,“ _1970_“,”_ 1981_“,”_1991_“,”_ 2001_“,”_ 201_“,”_ 201_“}
这是有问题的脚本:
Names Default To Here( 1 );
dt = Current Data Table();
numericColNames = dt << get column names( string, numeric );
For( i = 2, i <= N Items( numericColNames ), i++,
Eval(
Substitute(
Expr(
New Column( Char( numericColNames[i] ) || "_Canvi",
Numeric,
Continuous,
Format( "Percent", 12, 1 ),
X = i - 1,
Formula( (numericColNames[X] - numericColNames[i]) / numericColNames[X] )
)
),
Expr( __col__ ), Parse( ":Name (\!" " || numericColNames[i] || "\!")" )
)
)
);Re:在循环中如何指示其他列[I]您没有正确设置Substitute()函数。
代替和替代
Substitute()函数返回带有替换表达式的字符串的副本。该
替换为Into()函数会使用替换表达式更改原始字符串。
例如,请考虑以下脚本:
str1 = str2 = "All things considered";
str3 = Substitute( str1, "All", "Some" );
// str3 holds the result of the Substitute, and str1 is not changed
str4 = Substitute Into( str2, "All", "Some" );
// Substitute Into returns nothing, so str4 is missing, and str2 is changed
// and now holds the result of Substitute Into
Show( str1, str2, str3, str4 );
此脚本返回以下输出:
str1 =“考虑到所有事情”;
str2 =“考虑的一些事情”;
str3 =“考虑的一些事情”;
str4 =。;
我已经重写了你的脚本,我猜你想要的是什么
Names Default To Here( 1 );
dt = Current Data Table();
numericColNames = dt << get column names( string, numeric );
For( i = 2, i <= N Items( numericColNames ), i++,
Eval(
Substitute(
Expr(
New Column( Char( numericColNames[i] ) || "_Canvi",
Numeric,
Continuous,
Format( "Percent", 12, 1 ),
X = i - 1,
Formula( (__colX__ - __coli__ / __colX__ )
)
),
Expr( __coli__ ), Parse( ":Name (\!" " || numericColNames[i] || "\!")" ),
Expr( __colX__ ), Parse( ":Name (\!" " || numericColNames[X] || "\!")" )
)
)
);
Substitute()函数文档是从“脚本指南”中复制的
帮助==>图书==>脚本指南
Re:在循环中如何指示其他列[I]首先,感谢您的帮助。当我运行你的脚本时,我收到错误:
在以下脚本中,错误标记为/ * ### * /
替换/ * ### * /(Expr(...
由于列的名称是1980年的整数,因此您在过去的帖子中建议了这部分脚本。如果代替1980年它是“_1980_”,替代品可以被淘汰。
运营商是什么“\!”在“:名字”之后。
再次感谢您的教诲。
Re:在循环中如何指示其他列[I]1980列名称导致一个问题,通过在列规范周围放置:名称(“1980”)来解决该问题。 这不是使用Substitute()函数的原因。 Substitute()函数就在那里,因为您不希望为该列保存的公式具有该值
(numericColNames[X] - numericColNames[i]) / numericColNames[X] )
而是拥有价值
( __1980__ - __1960__ / __1980__ )
如果公式具有我指定的第一个语法,则意味着只要JMP会话更改以下任何值,公式就会失败:i,X,numericColNames。 换句话说,如果保存数据表,结束JMP会话,然后再次启动JMP,则新的JMP会话中的变量i,X或numericColNames都不会出现,因此当您打开数据表时,所有具有引用这些变量的公式的列将失败。
最后,我不确定您目前发现的问题是什么。 如果您可以提供数据样本,我至少有机会找出问题所在。
Re:在循环中如何指示其他列[I]再次问好。我打算计算随后在特鲁埃尔(西班牙)省市进行的连续人口普查中居民人数的变化百分比。我的意图是将人口普查与下一次人口普查进行比较。在我附上(部分)数据表的第一列中,记录了市镇的名称,在以下六个中,每个市镇的居民出现在不同的人口普查中。为了计算汇率,我计算了一次人口普查与下一次人口普查之间的差异,结果除以第一次人口普查,然后我将得到的值表示为百分比。即(_1842_ - _1877_)/ _1842_
