R:查找 data.frame 中的列索引

R: finding indices of columns in a data.frame

m <- lm(Sepal.Length ~ Sepal.Width + Petal.Width, data = iris)
beta = dfbetas(m)
> head(beta)
    (Intercept)   Sepal.Width   Petal.Width
1 -0.0018633253  0.0054762565 -0.0096031648
2  0.0094916858 -0.0062007468 -0.0137816086
3 -0.0221770886  0.0069280848  0.0540485812
4 -0.0408776612  0.0219247324  0.0731671391
5  0.0071436202 -0.0134636336  0.0150509697
6  0.0006264958 -0.0007979264  0.0001755277


apply(data.frame(beta), 2, function(x) which(abs(x) < 0.1632993))

我有一个名为 beta 的矩阵,其中包含 3 列。将其转换为类型 data.frame 后,我想使用绝对值 < 0.1632993 的观测值的 which 函数查找索引。本质上,我想要每列的索引列表。但是我的 apply 函数似乎没有做我想做的事情。

我们可以在整个数据集上使用 whicharr.ind=TRUE 来获得 row/column 索引

which(abs(beta) < 0.1632993, arr.ind=TRUE)