R - Running a t-test from piping operators

后端 未结 1 1385
北荒
北荒 2020-12-31 20:56

Is it possible to run a t.test from piping operators?
I tried to find the answer to this, but most of the questions around this topic look at d

相关标签:
1条回答
  • 2020-12-31 21:08

    We can place it inside summarise as a list

    d %>%
      summarise(ttest = list(t.test(amount ~ group, var.equal = TRUE))) 
    

    and if we need to extract only the pvalue, this can be done

    d %>% 
      summarise(pval = t.test(amount ~ group, var.equal = TRUE)$p.value)
    

    Or we can place it inside the {} and then do the t.test

    d %>%
         {t.test(.$amount ~ .$group, var.equal = TRUE)}
    

    Or without the braces by specifying the data for the formula method

    d %>%
         t.test(amount ~ group, data = ., var.equal = TRUE)
    

    EDIT: based on @hpesoj626's comments

    0 讨论(0)
提交回复
热议问题