Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从数据框中选择一个大于指定值的值。我的数据框仅包含单列
我正在尝试which.max函数,但它只返回数据框的第一个值
which.max
d[which.max(d$slope > 14.9),]
我想要一个单一的价值。第一个大于指定的
您可以按斜率对数据框进行排序,然后用于Position进行第一个匹配:
Position
dd <- d[order(d$slope), , drop = FALSE] dd$slope[Position(function(x) x > 14.9, dd$slope)]
Position只计算到第一个TRUE条件。它应该比使用which或全向量比较快得多。
TRUE
which
或者您可以使用which.min获取大于阈值的较低值:
which.min
d[d$slope > 14.9][which.min(d$slope[d$slope > 14.9]),]