r - 对数据集中每一行的列进行 t.test

标签 r dataframe statistics t-test hypothesis-test

我有一组数据 x,它包含 12 列和 167 行。第一列是每行的化合物 ID。我想为 3 列作为一组运行一个 t.test ,将其他 3 组作为第二组,分别为每一行运行。我的代码如下,但它不起作用。

for (i in 1:nrow(x)) {
 function(i)c(compound=i,
    t.test(x[2:4],x[8:10],
      x[x$compound==i, ],
      alternative='two.sided',conf.level=0.95)
    )
}
print(c(compound=i,t.test(x[2:4],x[8:10],x[x$compound==i,],
    alternative='two.sided',conf.level=0.95)))

我的意图是对 AC 组和 SC 组之间的每种代谢物(化合物)进行t.test,这是两组细胞。

compound    AC-1     AC-2     AC-3     AM-1      AM-2      AM-3      SC-1     SC-2     SC-3     SM-1      SM-2      SM-3
alanine     27612820 22338050 15359640 19741350  18726880  18510800  10914980 12071660 16036180 16890860  16066960  16364300
arginine    7067206  7172234  5933320  136272600 131596800 134717600 6102838  7186256  6770344  140127100 155341300 151748000
asparagine  3151398  2141378  1240904  11522180  8907711   9842342   1677299  2265826  2942991  11690360  12552660  12102620                        

最佳答案

x$stat <- sapply(1:nrow(x), function(i) t.test(as.numeric(as.character(unlist(x[i,2:4]))), as.numeric(as.character(unlist(x[i,8:10]))))[c("p.value")])

关于r - 对数据集中每一行的列进行 t.test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28119894/

相关文章:

python pandas 合并两个数据框并处理重复项?

r - R 中不同类型的聚合

c++ - 如何将卡方分布与 C++ Boost 库一起使用?

r - 如何向列表中的每个数据框添加一列

r - 根据 shinydashboard 中的选定选项卡更改元素的值

r - "effects"和 `aov` 返回的 `lm` 是什么?

c++ - 关于STDIN STDOUT STDERR的问题

从包含 R 中特定字符的字符串向量中删除条目

r - 随着数据框变大,如何防止 rbind() 变得非常慢?

c# - 将线性回归方程正确翻译为 C#