I am wondering how to tidy the following:
First I gather a selection of columns into a tibble with three columns: strain (=grouping factor), params (names of parameters) and values (the actual values)
sel <- t_tcellact %>% select(strain, contains("nbr_")) %>% gather(params, values, nbr_DP:nbr_CD3p)
Then I perform multiple pairwise.t.test():
test2 <- sel %>% bind_rows(sel) %>% split(.$params) %>% map(~ pairwise.t.test(x=.$values, g=.$strain, p.adj = "none"))
And the result is a list of the results from the pairwise.t.tests which I can start cleaning with:
test3 <- lapply(test2, tidy)
The list looks now like that:
$nbr_CD3p
group1 group2 p.value
1 SKG Balb/c 0.000001849548
$nbr_DN_CD69nCD25n
group1 group2 p.value
1 SKG Balb/c 0.6295371
and so on....
From this I need a tibble with following columns: parameter (e.g. nbr_CD3p), group1, group2, p.value.
In this example I had only two groups, but I want to do it in a generic way also applicable when I have multiple groups.
Does anybody have an idea how to get to this point in an elegant way (without a loop)?