Re: [R] Covert list of list to dataframe for export or outputting by(test) output

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 13 Sep 2005 - 06:21:55 EST

"Mike Bock" <mbock@Environcorp.com> writes:

> Greetings,
> I am running a buch of wilcox tests and need to be able to rapidly
> export the results into a csv file. I have attached example code as well
> as my attempts to get what I need. I have tried unlist,cbind,rbind etc
> but I am obvously missing something simple. FYI I am actually running
> about 50 WRS tests per dataset, this is just an example.
....
> WRS <- by(AKCCR, AKCCR$Compound.Name, function(AKCCR) wilcox.test(AdjRes
> ~ ExposureUnit, data = AKCCR))
> #just one of many attempts to get the output into a form I can write to
> a file and import into excel
> WRSlist <- cbind(WRS)
> WRSFinal <- data.frame(WRSlist)

How about do.call("rbind", WRS) instead? (Or just the first and hird column of it.)

A fine point: This gives a character matrix. If the function inside by() returned a data frame, then rbind()'ing would give one too, but one component of the return value of wilcox.test is NULL, so you need

> WRS <- by(AKCCR, AKCCR$Compound.Name, function(AKCCR)
+ as.data.frame(wilcox.test(AdjRes~ ExposureUnit, data = AKCCR)[-2])) Warning messages:
1: cannot compute exact p-value with ties in: wilcox.test.default(x =

   c(0.03, 0.24, 0.0082, 0.29, 0.01, 0.19, 2: cannot compute exact p-value with ties in: wilcox.test.default(x =

   c(0.15, 0.09, 0.16, 0.08, 0.15, 0.17,
> class(do.call("rbind", WRS))

[1] "data.frame"

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Sep 13 06:28:06 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:09 EST