2016-09-17 49 views
1
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類型後,我想使用which觀測值的函數查找絕對值爲< 0.1632993的索引。基本上我想要每列的索引列表。但我的應用功能似乎沒有做我想做的事情。R:找到data.frame中列的索引

+0

它可以是任何形式,只要它告訴我,這觀察(S)滿足我的腹肌的'標準(價值)<我的data.frame的每列的<0.1632993'。 – Adrian

+0

帶'arr.ind = TRUE'的'which'給出行/列索引 – akrun

回答

1

我們可以對整個數據集使用whicharr.ind=TRUE得到row/column指標

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