[R] Covert list of list to dataframe for export or outputting by(test) output
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Mon Sep 12 22:21:55 CEST 2005
"Mike Bock" <mbock at 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 at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list