gpt4 book ai didi

r - 如何找到大于或等于 a 的值,然后在 R 中找到这些最大值中的最小值?

转载 作者:行者123 更新时间:2023-12-02 01:50:42 25 4
gpt4 key购买 nike

a <- 0.6875
estFj <- c(-0.8231686, 0.1237904, 1.1967068, 1.3772572)

#What I tried so far is:

for(i in estFj) {
if (i >= a) {
t = c(i)
}
}

t

但它只给出了 1.3772572 的值,而我需要大于或等于 a 的所有 estFj 值,然后找到这些大于或等于 a 的值中的最小值!

如何解决这个问题?

最佳答案

我们可以使用向量化函数,找到大于 aestFj 值,然后找到这些值的最小值。

> estFj => a # returns a logical vector
[1] FALSE FALSE TRUE TRUE
estFj[estFj => a]
[1] 1.196707 1.377257 # uses the logical vector to subset the original vector
> min(estFj[estFj >= a]) # take the minimum of this
[1] 1.196707

关于r - 如何找到大于或等于 a 的值,然后在 R 中找到这些最大值中的最小值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70381984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com