0

我之前问过这个问题: 如何将应用函数的结果添加到现有数据框?

我想我可以用它作为模板,并且 unnest() 我的oddsratio测试结果到数据框。

这里有一些数字

thing<-matrix(c(33,2153,48,2528,1577,30335,66,1916,24,1162,15,910),nrow=6,byrow=T)
colnames(thing)<-c("SM","AE")
rownames(thing)<-c("a","b","c","d","e","f")
oddsratio(thing)

我希望如果我这样做:

oddsthing<-as.data.frame(thing)
oddsthing<-oddsthing%>%mutate(res=list(oddsratio(thing)))%>%unnest()

但它不会产生我希望的输出。

当我写

thing_list<-oddsratio(thing)

我可以在列表中看到四个元素:数据、度量、p.value、校正

如何从作为列附加到 SM AE 列右侧的列表中获取度量值和 pvalue?

如何访问列表中的内容?我可以 unnest($res) 但这也不起作用。

我有一种感觉,我快到了……

谢谢!

4

1 回答 1

2

通常,您可以使用View(thing_list)来查看列表的“结构”,或者在这里您可以使用names(thing_list)which 显示您"data" "measure" "p.value" "correction"。一旦您知道您可以 cbind.data.frame 将所需的列添加到您的数据框中,如下所示:

thing <- cbind.data.frame(thing, thing_list$measure, thing_list$p.value)
thing
    SM    AE  estimate     lower     upper  midp.exact              fisher.exact            chi.square
a   33  2153 1.0000000        NA        NA          NA                        NA                    NA
b   48  2528 0.8084932 0.5123434 1.2605062 0.350119674 0.36987910540283064353417 0.3468330287919010879
c 1577 30335 0.2962728 0.2051051 0.4121023 0.000000000 0.00000000000000007500751 0.0000000000002497838
d   66  1916 0.4461373 0.2888623 0.6758792 0.000115398 0.00014013356896922285933 0.0001160955897881125
e   24  1162 0.7408147 0.4366285 1.2754370 0.274390974 0.26665380954122580581256 0.2689008535316412263
f   15   910 0.9244444 0.5073984 1.7659563 0.804430890 0.87366076007998338948113 0.8167701545656785855
于 2019-06-05T11:35:57.037 回答