查找向量组合的索引值 [英] Finding the index values for a combination of vectors
本文介绍了查找向量组合的索引值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的可复制数据中,我想知道如何从满足以下条件的一对一匹配向量rs
&;hat
中找到元素的索引值:
rs < -1.96
ORrs > 1.96
元素对应的hat
元素为hat
>;max_hat
元素
是否可以在下图中绘制(使用text()
)其绘制圆旁边的索引值?
x <- readRDS(url("https://github.com/rnorouzian/s/raw/main/cooks.rds"))
hat <- readRDS(url("https://github.com/rnorouzian/s/raw/main/hat.rds"))
rs <- readRDS(url("https://github.com/rnorouzian/s/raw/main/rstudent.rds"))$z
plot(hat, rs, cex = 0.2+3*sqrt(x), pch = 19)
max_hat <- boxplot.stats(hat, coef = 2)$stats[5]
推荐答案
这两个条件都定义了逻辑向量SO和它们,并获得了它们对应的which
索引。然后绘制。
我添加了颜色以使文本标签更明显。
max_hat <- boxplot.stats(hat, coef = 2)$stats[5]
i <- abs(rs) > 1.96 # abs() because +/-1.96 are
# symmetric values
j <- hat > max_hat
k <- which(i & j)
plot(hat, rs, cex = 0.2+3*sqrt(x), pch = 19)
text(hat[k], rs[k], labels = names(k), pos = 2, col = "red")
这篇关于查找向量组合的索引值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文