user969113
user969113

Reputation: 2429

Transform output of the pairwise.wilcox.test test into a list

I want to transform the output matrix from the pairwise.wilcox.test:

> df <- data.frame(obs = c(rep("a", 10), rep("b", 10), rep("c", 10), rep("d", 10)), 

                   vars = c(runif(10, 1, 3), runif(10, 1, 6), runif(10, 3, 7), runif(10, 2, 9)))

> pairwise.wilcox.test(df$vars, df$obs)$p.value
             a          b         c
b 6.299985e-01         NA        NA
c 6.495053e-05 0.02052437        NA
d 6.495053e-05 0.01554483 0.6299985

into a list such as:

a  b  6.299985e-01
a  c  6.495053e-05
a  d  6.495053e-05
b  c  0.02052437
b  d  0.01554483
c  d  0.6299985

Is there any easy way of doing that?

Cheers!

Upvotes: 1

Views: 1540

Answers (1)

Pop
Pop

Reputation: 12401

You can use this

temp <-pairwise.wilcox.test(df$vars, df$obs)$p.value
df <- data.frame(expand.grid(dimnames(temp)),array(temp))
na.omit(df)

Upvotes: 2

Related Questions