Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按列对dplyr组_进行t检验_R_Dataframe_Dplyr - Fatal编程技术网

按列对dplyr组_进行t检验

按列对dplyr组_进行t检验,r,dataframe,dplyr,R,Dataframe,Dplyr,在问题的扩展中,我如何在新的数据帧中,基于生成的两组(A,B)即t.test(df$con1[df$cat1='A'],df$con1[df$cat1='B'])和t.test,为每个列((df$con2[df$cat1=='A'],df$con2[df$cat1=='B']) 我也遇到了同样的问题。我提出的最佳解决方案是将区分t检验的两个样本的变量分配到一个列表中: groups<-c(a,b) 组%select(需要列) } 我还没有完全调整到你的例子,但它应该让你非常接近。在我的

在问题的扩展中,我如何在新的数据帧中,基于生成的两组(
A
B
)即
t.test
df$con1[df$cat1='A']
df$con1[df$cat1='B']
)和
t.test,为每个列(
df$con2[df$cat1=='A']
df$con2[df$cat1=='B']


我也遇到了同样的问题。我提出的最佳解决方案是将区分t检验的两个样本的变量分配到一个列表中:

groups<-c(a,b)
组%select(需要列)
}

我还没有完全调整到你的例子,但它应该让你非常接近。在我的问题中,我需要对两个不同的样本(以col_a区分)进行多个时间段的t检验(加载到列表中并插入lappy以过滤col_b)。听起来几乎和您的问题一模一样。

在我看来,您最好在列表中获取
htest
类对象,而不是将输出强制到data.frame中。您可以通过(df,list(df$cat1,df$cat2),function(x)t.test(x$con1,x$con2))
返回所有组合的列表。如果您只需要
A-C,B-C
,那么您可以将输入数据集替换为
子集(df,cat1%在%C(“A”,“B”)&cat2==“C”)
@Vlo感谢您的建议。我想,我的解释把你弄糊涂了。我已经包括了更多关于我期望的细节,你现在可以看看这些组合了吗!谢谢。第一行已经对每个组合成对进行了t检验
A-C,B-C,A-E,B-E
@Vlo它正在计算两列
con1
con2
之间的t检验,这不是必需的。应在不同组的列中执行此操作。请看一看这个例子,如果它有意义的话。谢谢
df %>% group_by(cat1, cat2) %>% 
     summarise_each(funs(mean(., na.rm = TRUE),
                         sd(., na.rm = TRUE)), 
                    starts_with("con"))
groups<-c(a,b)
t_test_summary <- lapply(groups, function(x){

t.test(filter(df, col_a== con1 & col_b ==x) %>% select(col_wanted),filter(df, col_a== con2 & col_b ==x) %>% select(col_wanted))

}