-1

I need to do statistical tests in r for several combinations in a dataset. The end result needs to be published and I cant have to many tables. My workflow right now looks like this: I calculate t.tests with the pairwise.t.test function, then write the result to a csv table and combine later several of these csv tables in LO calc (or to an xls file if you want).

 ttestC30.class<- pairwise.t.test(LD$C30,LD$class)
 write.table(ttestC30.class$p.value, 'ttestC30.class.csv')
 ttestC100.class<- pairwise.t.test(LD$C100,LD$class)
 write.table(ttestC100.class$p.value, 'ttestC100.class.csv')
 ttestN30.class<- pairwise.t.test(LD$N30,LD$class)
 write.table(ttestN30.class$p.value, 'ttestN30.class.csv')

Each of the tables gives me an output like this:

        class1   class2  class3
class1   C30 
class2   C30     C30 
class3   C30     C30      C30 

In the end I would like to export it to my text document in something like the following format:

                class1             class2                  class3
class1   C30 / C100 / N30
class2   C30 / C100 / ...     … / … / ...
class3   C30 / C100 / ...     0.608 / 0.057 / 0.632   0.165 / 0.667 / 0.002

There must be a more convenient way to do this, no? A solution that is more generic than using pairwise.t.test would also be great, then I could repeat the same with other tests.

Edit: Reproducible example

attach(airquality)
a<- pairwise.t.test(Ozone, Month)
b<- pairwise.t.test(Temp, Month)

This is for example the output of a

round(a$p.value,3)
    May   Jun   Jul   Aug
Jun   1    NA    NA    NA
Jul   0 0.051    NA    NA
Aug   0 0.050 1.000    NA
Sep   1 1.000 0.005 0.004

And this is the output I would like, showing a and b combined:

      May  Jun         Jul        Aug
Jun   1/0  NA/NA       NA/NA      NA/NA
Jul   0/0  0.051/0.020 NA/NA      NA/NA
Aug   0/0  0.050/0.020 1.000/0.97 NA/NA
Sep   1/0  1.000/0.405 0.005/0.00 0.004/0
mace
  • 490
  • 1
  • 7
  • 24
  • 1
    When asking for help, you should provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data that can be run and tested. You are asking for a pretty unusual output format so it's likely going to require custom coding to get the formatting right. – MrFlick Dec 09 '15 at 15:37
  • Ok, I added an example. If someone has a different, but more approachable format that could work with 4-8 combined tables, then I am also open to that. – mace Dec 09 '15 at 15:53
  • This should work: `a <- round(a$p.value,3) b <- round(b$p.value,3) matrix(paste(a,b,sep="/"),nrow=nrow(a))` – Roman Dec 09 '15 at 15:55
  • Ok, yes thats doing the job. If you add it as an answer I will validate it. – mace Dec 09 '15 at 16:50

1 Answers1

0

We can try:

a <- round(a$p.value,3) 
b <- round(b$p.value,3)     
matrix(paste(a,b,sep="/"),nrow=nrow(a))
Roman
  • 17,008
  • 3
  • 36
  • 49