Maybe, this will be better: W <- as.matrix(lapply(Dataset[2:11], function(x) wilcox.test(x ~ GrFac, alternative="two.sided", data=Dataset)$statistic)) P <- as.matrix(lapply(Dataset[2:11], function(x) wilcox.test(x ~ GrFac, alternative="two.sided", data=Dataset)$p.value)) out <- rbind(as.numeric(W),as.numeric(P)) rownames(out) <- c("W", "p") colnames(out) <- paste(colnames(Dataset[2:11])) out
The output table we can format later in a spreadsheet (Calc, Excel, etc.). 2010/6/6 Iurie Malai <iurie.ma...@gmail.com> > Yes, Joris, my code (and output) is not perfect, but right now is > acceptable for me. Later I will try the options suggested by you. > > Thank you very much for your help! > > Iurie > > > > 2010/6/6 Joris Meys <jorism...@gmail.com> > >> 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.ma...@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 <jorism...@gmail.com> >> > >> >> # not tested >> >> out <- rbind(as.numeric(Wnew),as.numeric(P)) >> >> rownames(out) <- c("Wnew","P") >> >> >> >> >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help@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.m...@ugent.be >> ------------------------------- >> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php >> > > > > -- > Iurie Malai, Senior Lecturer > Department of Psychology > Faculty of Psychology and Special Education > Ion Creanga Moldova Pedagogical State University - www.upsm.md > http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University > [[alternative HTML version deleted]] ______________________________________________ R-help@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.