[R] getting elements out of list automatically

stephen sefick ssefick at gmail.com
Tue Jun 2 21:57:52 CEST 2009


o <- (structure(list(sand.silt = structure(list(statistic =
structure(185, .Names = "W"),
    parameter = NULL, p.value = 0.0478835773838087, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), gravel = structure(list(statistic =
structure(249.5, .Names = "W"),
    parameter = NULL, p.value = 0.528568586705971, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), cobble = structure(list(statistic =
structure(340, .Names = "W"),
    parameter = NULL, p.value = 0.195229999724195, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), boulder.bedrock = structure(list(statistic =
structure(368, .Names = "W"),
    parameter = NULL, p.value = 0.0193433582385429, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), fine.root = structure(list(statistic =
structure(395.5, .Names = "W"),
    parameter = NULL, p.value = 0.0147991488721795, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), course.root = structure(list(statistic =
structure(244.5, .Names = "W"),
    parameter = NULL, p.value = 0.202661704288995, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), wood = structure(list(statistic =
structure(289.5, .Names = "W"),
    parameter = NULL, p.value = 0.82819937730819, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), leaf = structure(list(statistic = structure(257,
.Names = "W"),
    parameter = NULL, p.value = 0.566029791094808, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), leaf.sand = structure(list(statistic =
structure(194, .Names = "W"),
    parameter = NULL, p.value = 0.0149634957806214, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), veg = structure(list(statistic = structure(399.5,
.Names = "W"),
    parameter = NULL, p.value = 0.0091447786580201, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest"), pool = structure(list(statistic = structure(273,
.Names = "W"),
    parameter = NULL, p.value = 0.776755854519814, null.value =
structure(0, .Names = "location shift"),
    alternative = "two.sided", method = "Wilcoxon rank sum test with
continuity correction",
    data.name = ".column by site"), .Names = c("statistic", "parameter",
"p.value", "null.value", "alternative", "method", "data.name"
), class = "htest")), .Names = c("sand.silt", "gravel", "cobble",
"boulder.bedrock", "fine.root", "course.root", "wood", "leaf",
"leaf.sand", "veg", "pool")))


I know that I can get the elements of this list that I want by

test <- rbind(c(o$veg$p.value, o$veg$statistic), c(o$pool$p.value,
o$pool$statistic))
colnames(test) <- c("p.value", "W")

is there any way to automate this process
-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

								-K. Mullis




More information about the R-help mailing list