Re: [R] Wilcoxon test output as a table

From: Joris Meys <jorismeys_at_gmail.com>
Date: Sat, 05 Jun 2010 23:59:22 +0200

Can't reproduce those with your code and your dataset. I also noticed some other unwanted behaviour by using as.numeric : it changes the formatting again. You won't get rid of the "" as that indicates it's a character, and you won't be able to format the numbers as the columns in a dataframe or in a matrix have all the same formatting.

If you want to generate output for a function or so, you can play around with cat() (see ?cat ). If it's for a report, think about using latex or HTML and the xtable package. There are other options, but that requires a bit more info.

And your code is not very optimal.

setwd("c:/Temp")
Dataset <- read.table("Dataset.txt",header=T,sep=",")

W <- apply(Dataset[2:11],2, function(x) wilcox.test(x ~ GrFac, alternative="two.sided", data=Dataset)$statistic) P <- apply(Dataset[2:11],2, function(x) wilcox.test(x ~ GrFac,

alternative="two.sided", data=Dataset)$p.value)
W <- format(W, digits = 5, nsmall = 2)
P <- format(P, digits = 1, nsmall = 3)

out <- rbind(W,P)
rownames(out) <- c("W","P")
colnames(out) <- colnames(Dataset[2:11])

If you know latex, you can use following package to get library(xtable)
xtable(out) # latex output

#html output
outtable <- xtable(out)
print(outtable,type="html")

On Sat, Jun 5, 2010 at 11:35 PM, Iurie Malai <iurie.malai_at_gmail.com> wrote:
> Thank you, Joris!
>
> I received two identical warnings:
>
> [14] WARNING: Warning in if (nchar(cmd) <= width) return(cmd) :
>  the condition has length > 1 and only the first element will be used
> [15] WARNING: Warning in if (nchar(cmd) <= width) return(cmd) :
>  the condition has length > 1 and only the first element will be used
>
> 2010/6/6 Joris Meys <jorismeys_at_gmail.com>
>
>> # not tested
>> out <- rbind(as.numeric(Wnew),as.numeric(P))
>> rownames(out) <- c("Wnew","P")
>>
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys_at_Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 05 Jun 2010 - 22:01:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Jun 2010 - 22:20:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive