chisq测试的结果如下所示,我只需要统计量(chisq)的总和,colsum不起作用。我怎么才能得到统计数据?
statistic parameter p.value
1 120 9 1.336165e-21
2 115.2397 21 5.292644e-15
3 114.9731 18 3.703771e-16
4 85.85785 21 8.283122e-10
5 103.7818 30 4.650999e-10
6 85.44727 24 8.062478e-09
7 42.03636 18 0.001093033
8 42.31688 24 0.01188941
9 72.22857 24 1.000100e-06
10 54.47273 24 0.0003685193
答案 0 :(得分:2)
你想要的东西是:
sum(object_name[ , 1]) # should work for matrix or dataframe
如果是data.frame,你可以写:
sum(object_name$statistic)
有时一个物体有一个矩阵埋在“一层以下”或甚至“两层以下”,应该。也许这个输出结果可能会被使用......不是说它和你的一样,但是它确实有一个列表类,它会打印出像你这样的结果:
object_name <-list(list(structure(c(1, 120, 9, 1.336165e-21, 2, 115.2397, 21,
5.292644e-15, 3, 114.9731, 18, 3.703771e-16, 4, 85.85785, 21,
8.283122e-10, 5, 103.7818, 30, 4.650999e-10, 6, 85.44727, 24,
8.062478e-09, 7, 42.03636, 18, 0.001093033, 8, 42.31688, 24,
0.01188941, 9, 72.22857, 24, 1.0001e-06, 10, 54.47273, 24, 0.0003685193
), .Dim = c(10L, 4L), .Dimnames = list(NULL, c("rown", "statistic",
"parameter", "p.value")))))
> str(object_name)
List of 1
$ :List of 1
..$ : num [1:10, 1:4] 1.00 1.20e+02 9.00 1.34e-21 2.00 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:4] "rown" "statistic" "parameter" "p.value"
您需要使用[[1]]两次才能“足够深”才能访问“统计”列:
object_name[[1]][[1]][ , "statistic"]
sum( object_name[[ 1 ]][[1]][, "statistic"] )
#[1] 267.6397