嘿,
我在R中有一个表格,格式如下
对于此表,我想应用以下函数为每行添加t.test值
table<- apply(table , 1,function(x) {
i <- as.numeric(x[3])
j <- as.numeric(x[4])
#Perform t.test
if( !is.na(i) && !is.na(j)){
test <- t.test( i, j, paired = TRUE)
out <- data.frame("Amino acids" = colnames(r)[r[1]],
"Tag" = colnames(r)[r[2]],
"LRatio 1" = colnames(r)[r[3]],
"LRatio 2" = colnames(r)[r[4]],
"Tvalue" = sprintf("%.3f", test$statistic),
"df" = test$parameter,
"Pvalue" = sprintf("%.3f", test$p.value))
return (out)
}
out <- data.frame("Amino acids" = colnames(r)[r[1]],
"Tag" = colnames(r)[r[2]],
"LRatio 1" = colnames(r)[r[3]],
"LRatio 2" = colnames(r)[r[4]],
"Tvalue" = "NA",
"df" = "NA",
"Pvalue" = "NA")
return (out)
})
我的t.test方法,抱怨我没有足够的&#39; x&#39;观测&#34;
调试我拥有的值的示例时:
i: -0.2480872
j: -0.1382415
x: merged.ac
A0A075B5K6, A0A0B4J1H6, P01629, P01630, P03976
merged.r2
127
merged.lratio.x
-0.2480872152
merged.lratio.y
-1.382415e-01
答案 0 :(得分:1)
这个问题的答案是t.test方法将两个非空数字向量作为参数。在上面的代码中,i和j是数值,因此x值不足的误差。