对R中的多行进行T检验 [英] T-test for multiple rows in R
问题描述
我有一个表,该表包含40多个列和200.000+行. 像这样:
I have a table with 40+ columns and 200.000+ rows. Something like this:
ID GROUP-A1 GROUP-A2 GROUP A3...A20 GROUP-B1 GROUP-B2 GROUP-B3...B20
1 5 6 3 5....3 10 21 9 15
2 3 4 6 2....13 23 42 34 23
3 5 3 1 0....12 10 12 43 15
4 0 0 2 5....3 10 21 23 15
我想对两组A(1..20)和B(1..20)进行一项t检验,以分别进行每项测量(每行),它们是独立的.并且可能将结果统计信息放在每行旁边的表中或在单独的表中,因此我可以轻松地选择重要的统计信息.
I would like to run a t-test for the two groups A (1..20) and B (1..20) for every measurement I have (each row), which are independent. And possibly, have the resulting stats in the table next to each row or in a separate table, so I can easily select the significant ones.
我查看了很少的R包,但是它们大多数都需要重新格式化我拥有的表,以将度量和组放入列中,在这种情况下,我将需要200.000+个单独的表.
I looked at few R packages but they mostly would require reformatting the table I have, to put measurements and groups in columns, and I would need 200.000+ separate tables in that case.
有什么主意吗?
推荐答案
像这样吗?
apply(df,1,function(x){t.test(x[2:21],x[22:41])})
要将测试统计信息或p值保存在新列中,您可以
To save the test statistic or p-value in a new column you could do
df$st=apply(df,1,function(x){t.test(x[2:21],x[22:41])$stat})
或$p.value
这篇关于对R中的多行进行T检验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!