【发布时间】:2017-03-27 04:00:23
【问题描述】:
我想获得重要项目的计数,即 60,您可以在执行 str(res.r) 时看到,您会看到以下字段没有我可以参考的名称。
通常情况下,我的数据是像data.frame(V1, V2),你可以做res.r$V1,但在这里你不能。
我也尝试过res.r$1,但也失败了。
# ..$ : chr [1:60] "cyl" "disp" "hp" "wt" ...
# ..$ : chr [1:2] "row" "col"
小例子
lista[[1]] 引用适用于最简单的示例
lista <- c( list(seq(1,5)), list(seq(1,7)) )
str(lista)
str(lista[[1]])
#List of 2
# $ : int [1:5] 1 2 3 4 5
# $ : int [1:7] 1 2 3 4 5 6 7
# int [1:5] 1 2 3 4 5
代码
res.r[[1]] 的引用在此处无法正常工作
library("corrplot")
library("psych")
library("gplots")
M.cor <- cor(mtcars)
p.mat <- psych::corr.test(M.cor, adjust = "none", ci = F)
alpha <- .0000005
plt.r <- corrplot(M.cor,
method = "color",
type = "upper",
tl.col = 'black',
diag = TRUE,
p.mat = p.mat[["r"]],
sig.level = alpha,
main = "r",
mar=c(0,0,1,0), # stackoverflow.com/a/14754408/…
)
# http://stackoverflow.com/a/40523080/54964
res.r <- which(p.mat[["r"]] < alpha, arr.ind = TRUE)
str(res.r)
# TODO here - how to get the count of significant item as num
输出
#Attaching package: ‘gplots’
#The following object is masked from ‘package:stats’:
# lowess
# int [1:60, 1:2] 2 3 4 6 11 1 5 7 8 9 ...
# - attr(*, "dimnames")=List of 2
# ..$ : chr [1:60] "cyl" "disp" "hp" "wt" ...
# ..$ : chr [1:2] "row" "col"
预期输出:重要项目的数量,这里是 60
R:3.3.1
操作系统:Debian 8.5
【问题讨论】: