除非达到特定总数,否则如何根据另一个变量的内容编写一个乘以数字的函数?
x * 1.45直到达到1000,如果达到1000,则停止。
编辑:
对于进一步的背景,我正在尝试计算贫困人口的数量,具体如下:
对于有6岁以下子女的家庭,该提案将逐步实施 反恐委员会以每美元收入45美分的比率开始 第一美元的收入。
对于年龄较大的孩子的家庭来说,每个阶段的费用为15美分 收入美元。
以下是我目前的情况,但不是很正确:
y <-
svrepdesign(
weights = ~marsupwt,
repweights = "pwwgt[1-9]",
type = "Fay",
rho = (1-1/sqrt(4)),
data = "asec15" ,
combined.weights = T ,
dbtype = "MonetDBLite" ,
dbname = dbfolder
)
f = function(x) if (x < 1000) exp(seq(log(x), log(1000), by=log(1.15))) else x
c = function(x) if (x < 2000) exp(seq(log(x), log(2000), by=log(1.45))) else x
CTC_Update <-subset(
y ,
(spmu_numkids == 0 & spmu_resources < spmu_povthreshold) |
(spmu_numkids == 1 & fownu6 == 0 & spmu_resources - spmu_actc + 1*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 2 & fownu6 == 0 & spmu_resources - spmu_actc + 2*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 3 & fownu6 == 0 & spmu_resources - spmu_actc + 3*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 4 & fownu6 == 0 & spmu_resources - spmu_actc + 4*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 5 & fownu6 == 0 & spmu_resources - spmu_actc + 5*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 6 & fownu6 == 0 & spmu_resources - spmu_actc + 6*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 7 & fownu6 == 0 & spmu_resources - spmu_actc + 7*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 8 & fownu6 == 0 & spmu_resources - spmu_actc + 8*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 9 & fownu6 == 0 & spmu_resources - spmu_actc + 9*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 10 & fownu6 == 0 & spmu_resources - spmu_actc + 10*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 11 & fownu6 == 0 & spmu_resources - spmu_actc + 11*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 12 & fownu6 == 0 & spmu_resources - spmu_actc + 12*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 13 & fownu6 == 0 & spmu_resources - spmu_actc + 13*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 14 & fownu6 == 0 & spmu_resources - spmu_actc + 14*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 15 & fownu6 == 0 & spmu_resources - spmu_actc + 15*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 16 & fownu6 == 0 & spmu_resources - spmu_actc + 16*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 17 & fownu6 == 0 & spmu_resources - spmu_actc + 17*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 18 & fownu6 == 0 & spmu_resources - spmu_actc + 18*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 19 & fownu6 == 0 & spmu_resources - spmu_actc + 19*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids >= 20 & fownu6 == 0 & spmu_resources - spmu_actc + 20*f(ftotval) + 0*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 1 & fownu6 == 1 & spmu_resources - spmu_actc + 1*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 2 & fownu6 == 1 & spmu_resources - spmu_actc + 2*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 3 & fownu6 == 1 & spmu_resources - spmu_actc + 3*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 4 & fownu6 == 1 & spmu_resources - spmu_actc + 4*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 5 & fownu6 == 1 & spmu_resources - spmu_actc + 5*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 6 & fownu6 == 1 & spmu_resources - spmu_actc + 6*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 7 & fownu6 == 1 & spmu_resources - spmu_actc + 7*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 8 & fownu6 == 1 & spmu_resources - spmu_actc + 8*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 9 & fownu6 == 1 & spmu_resources - spmu_actc + 9*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 10 & fownu6 == 1 & spmu_resources - spmu_actc + 10*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 11 & fownu6 == 1 & spmu_resources - spmu_actc + 11*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 12 & fownu6 == 1 & spmu_resources - spmu_actc + 12*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 13 & fownu6 == 1 & spmu_resources - spmu_actc + 13*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 14 & fownu6 == 1 & spmu_resources - spmu_actc + 14*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 15 & fownu6 == 1 & spmu_resources - spmu_actc + 15*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 16 & fownu6 == 1 & spmu_resources - spmu_actc + 16*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 17 & fownu6 == 1 & spmu_resources - spmu_actc + 17*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 18 & fownu6 == 1 & spmu_resources - spmu_actc + 18*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 19 & fownu6 == 1 & spmu_resources - spmu_actc + 19*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids >= 20 & fownu6 == 1 & spmu_resources - spmu_actc + 20*f(ftotval) + 1*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 1 & fownu6 == 2 & spmu_resources - spmu_actc + 1*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 2 & fownu6 == 2 & spmu_resources - spmu_actc + 2*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 3 & fownu6 == 2 & spmu_resources - spmu_actc + 3*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 4 & fownu6 == 2 & spmu_resources - spmu_actc + 4*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 5 & fownu6 == 2 & spmu_resources - spmu_actc + 5*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 6 & fownu6 == 2 & spmu_resources - spmu_actc + 6*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 7 & fownu6 == 2 & spmu_resources - spmu_actc + 7*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 8 & fownu6 == 2 & spmu_resources - spmu_actc + 8*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 9 & fownu6 == 2 & spmu_resources - spmu_actc + 9*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 10 & fownu6 == 2 & spmu_resources - spmu_actc + 10*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 11 & fownu6 == 2 & spmu_resources - spmu_actc + 11*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 12 & fownu6 == 2 & spmu_resources - spmu_actc + 12*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 13 & fownu6 == 2 & spmu_resources - spmu_actc + 13*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 14 & fownu6 == 2 & spmu_resources - spmu_actc + 14*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 15 & fownu6 == 2 & spmu_resources - spmu_actc + 15*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 16 & fownu6 == 2 & spmu_resources - spmu_actc + 16*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 17 & fownu6 == 2 & spmu_resources - spmu_actc + 17*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 18 & fownu6 == 2 & spmu_resources - spmu_actc + 18*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 19 & fownu6 == 2 & spmu_resources - spmu_actc + 19*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids >= 20 & fownu6 == 2 & spmu_resources - spmu_actc + 20*f(ftotval) + 2*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 1 & fownu6 == 3 & spmu_resources - spmu_actc + 1*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 2 & fownu6 == 3 & spmu_resources - spmu_actc + 2*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 3 & fownu6 == 3 & spmu_resources - spmu_actc + 3*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 4 & fownu6 == 3 & spmu_resources - spmu_actc + 4*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 5 & fownu6 == 3 & spmu_resources - spmu_actc + 5*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 6 & fownu6 == 3 & spmu_resources - spmu_actc + 6*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 7 & fownu6 == 3 & spmu_resources - spmu_actc + 7*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 8 & fownu6 == 3 & spmu_resources - spmu_actc + 8*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 9 & fownu6 == 3 & spmu_resources - spmu_actc + 9*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 10 & fownu6 == 3 & spmu_resources - spmu_actc + 10*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 11 & fownu6 == 3 & spmu_resources - spmu_actc + 11*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 12 & fownu6 == 3 & spmu_resources - spmu_actc + 12*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 13 & fownu6 == 3 & spmu_resources - spmu_actc + 13*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 14 & fownu6 == 3 & spmu_resources - spmu_actc + 14*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 15 & fownu6 == 3 & spmu_resources - spmu_actc + 15*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 16 & fownu6 == 3 & spmu_resources - spmu_actc + 16*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 17 & fownu6 == 3 & spmu_resources - spmu_actc + 17*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 18 & fownu6 == 3 & spmu_resources - spmu_actc + 18*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 19 & fownu6 == 3 & spmu_resources - spmu_actc + 19*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids >= 20 & fownu6 == 3 & spmu_resources - spmu_actc + 20*f(ftotval) + 3*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 1 & fownu6 == 4 & spmu_resources - spmu_actc + 1*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 2 & fownu6 == 4 & spmu_resources - spmu_actc + 2*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 3 & fownu6 == 4 & spmu_resources - spmu_actc + 3*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 4 & fownu6 == 4 & spmu_resources - spmu_actc + 4*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 5 & fownu6 == 4 & spmu_resources - spmu_actc + 5*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 6 & fownu6 == 4 & spmu_resources - spmu_actc + 6*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 7 & fownu6 == 4 & spmu_resources - spmu_actc + 7*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 8 & fownu6 == 4 & spmu_resources - spmu_actc + 8*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 9 & fownu6 == 4 & spmu_resources - spmu_actc + 9*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 10 & fownu6 == 4 & spmu_resources - spmu_actc + 10*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 11 & fownu6 == 4 & spmu_resources - spmu_actc + 11*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 12 & fownu6 == 4 & spmu_resources - spmu_actc + 12*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 13 & fownu6 == 4 & spmu_resources - spmu_actc + 13*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 14 & fownu6 == 4 & spmu_resources - spmu_actc + 14*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 15 & fownu6 == 4 & spmu_resources - spmu_actc + 15*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 16 & fownu6 == 4 & spmu_resources - spmu_actc + 16*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 17 & fownu6 == 4 & spmu_resources - spmu_actc + 17*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 18 & fownu6 == 4 & spmu_resources - spmu_actc + 18*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 19 & fownu6 == 4 & spmu_resources - spmu_actc + 19*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids >= 20 & fownu6 == 4 & spmu_resources - spmu_actc + 20*f(ftotval) + 4*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 1 & fownu6 == 5 & spmu_resources - spmu_actc + 1*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 2 & fownu6 == 5 & spmu_resources - spmu_actc + 2*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 3 & fownu6 == 5 & spmu_resources - spmu_actc + 3*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 4 & fownu6 == 5 & spmu_resources - spmu_actc + 4*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 5 & fownu6 == 5 & spmu_resources - spmu_actc + 5*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 6 & fownu6 == 5 & spmu_resources - spmu_actc + 6*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 7 & fownu6 == 5 & spmu_resources - spmu_actc + 7*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 8 & fownu6 == 5 & spmu_resources - spmu_actc + 8*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 9 & fownu6 == 5 & spmu_resources - spmu_actc + 9*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 10 & fownu6 == 5 & spmu_resources - spmu_actc + 10*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 11 & fownu6 == 5 & spmu_resources - spmu_actc + 11*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 12 & fownu6 == 5 & spmu_resources - spmu_actc + 12*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 13 & fownu6 == 5 & spmu_resources - spmu_actc + 13*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 14 & fownu6 == 5 & spmu_resources - spmu_actc + 14*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 15 & fownu6 == 5 & spmu_resources - spmu_actc + 15*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 16 & fownu6 == 5 & spmu_resources - spmu_actc + 16*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 17 & fownu6 == 5 & spmu_resources - spmu_actc + 17*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 18 & fownu6 == 5 & spmu_resources - spmu_actc + 18*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 19 & fownu6 == 5 & spmu_resources - spmu_actc + 19*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids >= 20 & fownu6 == 5 & spmu_resources - spmu_actc + 20*f(ftotval) + 5*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 1 & fownu6 == 6 & spmu_resources - spmu_actc + 1*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 2 & fownu6 == 6 & spmu_resources - spmu_actc + 2*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 3 & fownu6 == 6 & spmu_resources - spmu_actc + 3*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 4 & fownu6 == 6 & spmu_resources - spmu_actc + 4*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 5 & fownu6 == 6 & spmu_resources - spmu_actc + 5*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 6 & fownu6 == 6 & spmu_resources - spmu_actc + 6*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 7 & fownu6 == 6 & spmu_resources - spmu_actc + 7*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 8 & fownu6 == 6 & spmu_resources - spmu_actc + 8*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 9 & fownu6 == 6 & spmu_resources - spmu_actc + 9*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 10 & fownu6 == 6 & spmu_resources - spmu_actc + 10*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 11 & fownu6 == 6 & spmu_resources - spmu_actc + 11*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 12 & fownu6 == 6 & spmu_resources - spmu_actc + 12*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 13 & fownu6 == 6 & spmu_resources - spmu_actc + 13*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 14 & fownu6 == 6 & spmu_resources - spmu_actc + 14*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 15 & fownu6 == 6 & spmu_resources - spmu_actc + 15*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 16 & fownu6 == 6 & spmu_resources - spmu_actc + 16*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 17 & fownu6 == 6 & spmu_resources - spmu_actc + 17*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 18 & fownu6 == 6 & spmu_resources - spmu_actc + 18*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids == 19 & fownu6 == 6 & spmu_resources - spmu_actc + 19*f(ftotval) + 6*c(ftotval) < spmu_povthreshold) |
(spmu_numkids >= 20 & fownu6 == 6 & spmu_resources - spmu_actc + 20*f(ftotval) + 6*c(ftotval) < spmu_povthreshold))
答案 0 :(得分:5)
我做......
f = function(x) if (x > 1000) exp(seq(log(x), log(1000), by=log(.45))) else x
# example
f(100000)
[1] 100000.000 45000.000 20250.000 9112.500 4100.625 1845.281
seq(from, to, by)
不会传递to
(显示过去1000的下一个数字),但如果你想要,只需将它添加到矢量的末尾(再次除以.45)。
exp
和log
业务来自..
log(x*.45^y) = log(x) + y*log(.45)
答案 1 :(得分:3)
这是一个非常适合递归函数的任务:
f <- function(x, coeff, threshold){
t <- tail(x,1)
if (t*coeff<threshold)
return(x)
f(c(x, t*coeff), coeff, threshold)
}
f(x = 100000, coeff = 0.45, threshold = 1000)
#[1] 100000.000 45000.000 20250.000 9112.500 4100.625 1845.281
答案 2 :(得分:2)
这是你想要的吗?
MultiplyUntil <- function(x,y,threshhold) {
repeat
{
print(x)
x <- x * y
if (x < threshhold)
{
print(x)
break
}
if (x > threshhold & y > 1)
{
print("Will go to infinity")
break
}
}
}
在您的示例中x <- x
,y <- .45
和threshhold <- 1000
:
# with x = 10000
MultiplyUntil(10000, .45, 1000)
# [1] 10000
# [1] 4500
# [1] 2025
# [1] 911.25
答案 3 :(得分:2)
首先,我们定义一个函数,将给定的起始值乘以比率r
(以创建几何系列),尽可能多次,而不传递给定的阈值
f = function(start, r, threshold){
N = floor(log(threshold/start) / log(r))
r^(0:N) * start
}
现在,将此应用于您的
示例“x * 1.45直到达到1000,如果达到1000,则停止。”
对于10的起始值(x
),我们可以
x = 10
f(x, 1.45, 1000)
# [1] 10.00000 14.50000 21.02500 30.48625 44.20506 64.09734 92.94114
# [8] 134.76466 195.40876 283.34269 410.84691 595.72802 863.80562
如果您还希望在系列中包含下一个值(即超过阈值的第一个值),则可以在函数中使用ceiling
intead floor
。