[R] Wilcoxon test output as a table
Joris Meys
jorismeys at gmail.com
Sat Jun 5 23:59:22 CEST 2010
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
More information about the R-help
mailing list