jrubins
jrubins

Reputation: 197

How to get a matrix of mean differences between groups in R

I'm doing a bunch of T-tests using the pairwise.t.test function in R, which creates a snazzy matrix of P values for all the comparisons like

date    p.value.2016.04.18  p.value.2016.04.20  p.value.2016.04.22
2016-04-20  1.00E+00    NA  NA
2016-04-22  1.00E+00    1.22E-01    NA
2016-04-24  1.00E+00    1.00E+00    1.00E+00
2016-04-26  1.00E+00    5.01E-01    1.00E+00
2016-04-28  1.28E-02    1.03E-01    6.20E-06

I'd like to make a matching matrix of differences between the means of the groups. My google-fu has failed me. Can you help a humble stats monkey out, SO?

Upvotes: 0

Views: 222

Answers (1)

Hack-R
Hack-R

Reputation: 23216

Here's an example from this famous listserv:

Table1 <- matrix(10:6, ncol = 1)
rownames(Table1) <- letters[1:5]
Table1

t(outer(Table1[,1], Table1[,1], `-`))

Upvotes: 1

Related Questions