How to melt pairwise.wilcox.test output using dplyr?

后端 未结 2 1225
野性不改
野性不改 2020-12-12 06:52

I want to apply pairwise.wilcox.test for multiple independent variables at a time and then want to have the output in long format. For a particular Wavelength,

2条回答
  •  悲&欢浪女
    2020-12-12 07:29

    A bit verbose and Im sure it could be made more efficient:

    library(tidyverse)
    library(broom)
    res <- 
      tbl_df(df)%>% 
      pivot_longer(cols = -Class, names_to = "Wavelengths", values_to = "value") %>% 
      group_by(Wavelengths) %>% 
      summarise(pw_wt = list(pairwise.wilcox.test(value,as.factor(Class),
                                                  p.adjust.method = "bonf")$p.value)) %>% 
      ungroup() %>% 
      mutate(pw_wt_t = map(pw_wt, broom::tidy)) %>% 
      unnest(pw_wt_t)
    

提交回复
热议问题