在 FoxPro 中为新行乘以和减去前一行中的值 [英] Multiply and subtract values in previous row for new row in FoxPro
问题描述
我正在尝试在 fox pro 中编写命令来帮助我计算看起来像这样的表中的两个变量
age death_rate 活着 死了1 0.003 1000 32 0.001 997 13 0.00064 0.0055 0.002...
在 x 岁存活 =(在 x-1 岁存活)-(在 x-1 岁死亡)
x 岁死亡 =(x 岁死亡率)*(x 岁活着)
我正在尝试自动计算活着和死亡的其余值,但两个空列在计算中相互依赖,我不确定命令应该是什么样子
我不能给你一个命令来做到这一点,但如果你使用一个小程序,它相对容易.我不知道您使用的是什么数据文件类型(VFP 表、MSSQL 表),因此我将使用 VFP 游标进行演示.您可以通过在命令窗口中键入 MODIFY COMMAND 在 VFP 中打开一个新的程序窗口.将以下代码粘贴到程序窗口中,突出显示代码,右键单击并执行选择.
CREATE CURSOR 死亡率 (age i,death_rate n(6,4),alive i, dead i)插入死亡率 (age,death_rate,alive,dead) VALUES (1,.003,1000,3)INSERT INTO 死亡率 (age,death_rate,alive,dead) VALUES (2,.001,997,1)INSERT INTO 死亡率 (age,death_rate,alive,dead) VALUES (3,.0006,0,0)插入死亡率 (age,death_rate,alive,dead) VALUES (4,.005,0,0)插入死亡率 (age,death_rate,alive,dead) VALUES (5,.002,0,0)转到 2 &&您已提供前 2 个值,转到记录 2散点名 oprev &&创建当前记录的分散对象,然后...跳过&&跳过 1 条记录扫描休息用 oprev.alive 替换活着 - oprev.dead,用轮子死了(死亡率 * 活着,0)散点名 oprev &&跳到下一条记录前刷新端扫描浏览正常最后
结果是:
<块引用> AGE DEATH_RATE ALIVE DEAD1 0.0030 1000 32 0.0010 997 13 0.0006 996 14 0.0050 995 55 0.0020 990 2
I'm trying to write command in fox pro that helps me calculate two variables in a table that looks like this
age death_rate alive dead
1 0.003 1000 3
2 0.001 997 1
3 0.0006
4 0.005
5 0.002
...
alive at age x = (alive at age x-1) - (dead at age x-1)
dead at age x = (death_rate at age x) * (alive at age x)
I'm trying to calculate rest of the values for alive and dead automatically but the two empty columns are dependent on each other in calculation, I'm not sure how the command should look like
I cannot give you one command to do this, but it is relatively easy if you use a small program. I don't know what data file type you are using (VFP table, MSSQL table) so I will demonstrate with a VFP cursor. You can open a new program window in VFP by typing MODIFY COMMAND in the command window. Paste the following code in the Program window, highlight the code, right-click and Execute Selection.
CREATE CURSOR deathrate (age i,death_rate n(6,4),alive i, dead i)
INSERT INTO deathrate (age,death_rate,alive,dead) VALUES (1,.003,1000,3)
INSERT INTO deathrate (age,death_rate,alive,dead) VALUES (2,.001,997,1)
INSERT INTO deathrate (age,death_rate,alive,dead) VALUES (3,.0006,0,0)
INSERT INTO deathrate (age,death_rate,alive,dead) VALUES (4,.005,0,0)
INSERT INTO deathrate (age,death_rate,alive,dead) VALUES (5,.002,0,0)
GOTO 2 && you have supplied the first 2 values, go to record 2
SCATTER NAME oprev && create a scattered object of the current record, then...
SKIP && skip 1 record
SCAN rest
replace alive WITH oprev.alive - oprev.dead, dead WITH round(death_rate * alive,0)
SCATTER NAME oprev && refresh before skipping to next record
ENDSCAN
BROWSE NORMAL LAST
The result is:
AGE DEATH_RATE ALIVE DEAD 1 0.0030 1000 3 2 0.0010 997 1 3 0.0006 996 1 4 0.0050 995 5 5 0.0020 990 2
这篇关于在 FoxPro 中为新行乘以和减去前一行中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!