R 如何得到y最大的x?

R 如何得到y最大的x?,r,R,没有循环。 下面给出了两个分布之间的最大差异(y值) x.e@docendo discimus,@danas.zuokas,thx寻求帮助。:) 所以它是这样的: x.e <- ecdf(x) y.e <- ecdf(y) mx <- max(x,y) steps <- seq(0,mx,mx/1000) dif <- abs(x.e(steps) - y.e(steps)) y.max <- max(dif) x.max <- st

没有循环。

下面给出了两个分布之间的最大差异(y值)


x.e@docendo discimus,@danas.zuokas,thx寻求帮助。:)

所以它是这样的:

x.e <- ecdf(x)
y.e <- ecdf(y)
mx <- max(x,y)

  steps <- seq(0,mx,mx/1000)
  dif <- abs(x.e(steps) - y.e(steps))

  y.max <- max(dif)
  x.max <- steps[which.max(dif)]  

x.e一般来说,您可以使用
which(x==max(x))
获取所有索引的最大值索引,或者使用
which.max(x)
仅获取第一个最大值索引。
x.e <- ecdf(x)
y.e <- ecdf(y)
mx <- max(x,y)

  steps <- seq(0,mx,mx/1000)
  dif <- abs(x.e(steps) - y.e(steps))

  y.max <- max(dif)
  x.max <- steps[which.max(dif)]