您可以将数据通过管道传输到 pairwise.t.test 中吗?

Can you pipe data into a pairwise.t.test?

我想知道是否可以简化以下代码以允许数据直接从 summarize 命令传输到 pairwise.t.test,而不创建中间对象?

data_for_PTT <- data %>% 
  group_by(subj, TT) %>% 
  summarise(meanRT = mean(RT))

pairwise.t.test(x = data_for_PTT$meanRT, g = data_for_PTT$TT, paired = TRUE)

我试过x = .$meanRT但不喜欢,返回:

Error in match.arg(p.adjust.method) : 'arg' must be NULL or a character vector

可以使用大括号:

data_for_PTT <- data %>% 
  group_by(subj, TT) %>% 
  summarise(meanRT = mean(RT)) %>%
  {pairwise.t.test(x = .$meanRT, g = .$TT, paired = TRUE)}

可重现:

df <- data.frame(X1 = runif(1000), X2 = runif(1000), subj = rep(c("A", "B")))

df %>% 
  {pairwise.t.test(.$X1, .$subj, paired = TRUE)}