用一个x变量将Y值降低到所需值 [英] Drop Y value till desired value with ONE x variable

查看:68
本文介绍了用一个x变量将Y值降低到所需值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一个重要变量来降低Y的值。

I am trying to drop the value of Y with one important variable.

Y的起始值为2.4,端点为1.7。问题是我不知道2.4和1.7之间的数据。 (唯一的线索是,它总是取决于X的值并一直下降到命中1.7)。

Y starts with value of 2.4 and endpoint is 1.7. The problem is I do not know the data between 2.4 and 1.7. (Only clue is it always depends on the value of X and drops til hit 1.7)

如果X值较大,Y值应下降更多。 (X值介于0到8之间)。

If X value is big, Y should drop more. (X value is between 0 ~ 8).

如果值很小,则应减少的幅度较小。

If it is small, it should drop less.

任何人都可以提供建议吗?还是一种表演方式?

Anyone can give an advice? or a way to perform?

下面是示例数据。

Y     X
2.4   1   
?     7  
?     3
?     5
?     8 
1.7   3


推荐答案

一种方法是:

start = 2.4
end = 1.7

df$Y <- c(start, start - cumsum(df$X[-1] * (start - end)/sum(df$X[-1])))

#  X        Y
#1 1 2.400000
#2 7 2.211538
#3 3 2.130769
#4 5 1.996154
#5 8 1.780769
#6 3 1.700000






我们来分解一下。 df $ X 是确定下降幅度的数字


Let's break this down. df$X is the numbers which determines the magnitude of drop

df$X
#[1] 1 7 3 5 8 3

我们这样做的时候

(start - end)/sum(df$X[-1])
#[1] 0.02692308

它给出了1个单位的掉落量。由于我们已经有了该数字( 2.4 ),因此我们将忽略第一个值,并且我们不想将其用于计算。

It gives us how much 1 unit of drop is. We are ignoring the first value since we already have that number (2.4) and we don't want to take that into calculation.

现在,我们将其乘以 X ,这样当数字为7时,跌幅会更高;当数字为1时,跌幅会更低

Now we multiply it by X so that when the number is 7 we will get higher drop, when it is 1 the drop will be lower

df$X[-1] * (start - end)/sum(df$X[-1])
#[1] 0.18846154 0.08076923 0.13461538 0.21538462 0.08076923

df $ X进行比较时您会注意到

0.02692308 * 7 = 0.1884615
0.02692308 * 3 = 0.08076923
0.02692308 * 5 = 0.1346154

依此类推。

最后,我们通过将所有这些数字相加得出总和(总金额),并从开始,这样我们就可以根据相应的 X 得到相对下降了。

Finally we take cumulative sum (cumsum) by adding all these numbers which we subtract it from start so that we now have relative drops according to corresponding X.

这篇关于用一个x变量将Y值降低到所需值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆