Mike Bock
2005-Sep-12 19:32 UTC
[R] Covert list of list to dataframe for export or outputting by(test) output
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.
Thanks 10^6
Mike
AKCCR <-
structure(list(ExposureUnit = structure(as.integer(c(1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2)), .Label = c("Reference",
"Study"), class "factor"),
Compound.Name = structure(as.integer(c(1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), .Label
c("Acenaphthene",
"Cadmium, Total"), class = "factor"), AdjRes = c(0.03,
0.24,
0.0082, 0.29, 0.01, 0.19, 0.2, 0.22, 0.0032, 0.32, 0.09,
0.3, 0.0061, 0.0037, 0.38, 0.2, 0.36, 0.09, 0.77, 0.2, 0.19,
0.2, 0.18, 0.6, 0.32, 0.34, 1.5, 1.2, 0.21, 0.21, 0.01, 0.2,
0.32, 0.2, 0.19, 0.02, 0.26, 0.37, 0.18, 1.3, 0.0088, 4.78,
0.0033, 0.32, 2.1, 0.19, 0.01, 0.3, 1.4, 0.21, 0.29, 1.4,
0.19, 0.21, 0.15, 0.09, 0.16, 0.08, 0.15, 0.17, 0.12, 0.07,
0.46, 0.13, 0.43, 0.09, 0.26, 1.65, 0.21, 0.28, 0.3, 0.22,
0.28, 0.19, 0.21, 0.14, 0.17, 0.15, 0.19, 0.16, 2.78, 0.52,
0.16, 1.35, 0.17, 0.65, 0.17, 0.25, 0.21, 0.17, 0.17, 0.27,
0.24, 0.19, 0.23, 0.15)), .Names = c("ExposureUnit",
"Compound.Name",
"AdjRes"), class = "data.frame", row.names =
c("1", "2", "3",
"4", "5", "6", "7", "8",
"9", "10", "11", "12", "13",
"14", "15",
"16", "17", "18", "19", "20",
"21", "22", "23", "24", "25",
"26",
"27", "28", "29", "30", "31",
"32", "33", "34", "35", "36",
"37",
"38", "39", "40", "41", "42",
"43", "44", "45", "46", "47",
"48",
"49", "50", "51", "52", "53",
"54", "55", "56", "57", "58",
"59",
"60", "61", "62", "63", "64",
"65", "66", "67", "68", "69",
"70",
"71", "72", "73", "74", "75",
"76", "77", "78", "79", "80",
"81",
"82", "83", "84", "85", "86",
"87", "88", "89", "90", "91",
"92",
"93", "94", "95", "96"))
attach(AKCCR)
Means <- tapply( AdjRes, list(Compound.Name,ExposureUnit), mean , na.rm
= TRUE)
SdDev <- tapply( AdjRes, list(Compound.Name,ExposureUnit), sd , na.rm TRUE)
Samples <- tapply( AdjRes, list(Compound.Name,ExposureUnit), function(x)
sum(!is.na(x)))
#ttest <- by(AKCCR, AKCCR$Compound.Name, function(AKCCR) t.test(AdjRes ~
ExposureUnit, data = AKCCR))
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)
Michael Bock, PhD.
ENVIRON International Corporation
477 Congress Street, Fifth Floor
Portland, ME 04101
phone: 207.523.3469
fax: 207.773.8597
[[alternative HTML version deleted]]
Peter Dalgaard
2005-Sep-12 20:21 UTC
[R] Covert list of list to dataframe for export or outputting by(test) output
"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
Chris Buddenhagen, Botany Department, Charles Darwin Research Station, Santa Cruz,Galapagos. Mail: Charles Darwin Foundation, Casilla 17-01-3891 Avenida 6 de Diciembre N36-109 y Pasaje California Quito, ECUADOR Dear R experts Is there a simple means of doing this multiple comparison test in R? I did a search and found information about it at http://finzi.psych.upenn.edu/R/Rhelp02a/archive/44566.html but it did not include information about doing it in R. Chris Buddenhagen, Botany Department, Charles Darwin Research Station, Santa Cruz,Galapagos. Mail: Charles Darwin Foundation, Casilla 17-01-3891 Avenida 6 de Diciembre N36-109 y Pasaje California Quito, ECUADOR ______________________________________________________________________ EL CONTENIDO DE ESTE MENSAJE ES DE ABSOLUTA RESPONSABILIDAD DEL AUTOR. FUNDACION CHARLES DARWIN WWW.DARWINFOUNDATION.ORG