[R] getting elements out of list automatically

stephen sefick ssefick at gmail.com
Tue Jun 2 22:53:27 CEST 2009


yes sorry for not being clearer.  Thank you very much.
regards,

Stephen Sefick

On Tue, Jun 2, 2009 at 4:37 PM, jim holtman <jholtman at gmail.com> wrote:
> Is this what you want:
>
>> x <- lapply(o, function(z) c(P.value=z$p.value, W=z$statistic))
>> do.call(rbind,x)
>                     P.value   W.W
> sand.silt       0.047883577 185.0
> gravel          0.528568587 249.5
> cobble          0.195230000 340.0
> boulder.bedrock 0.019343358 368.0
> fine.root       0.014799149 395.5
> course.root     0.202661704 244.5
> wood            0.828199377 289.5
> leaf            0.566029791 257.0
> leaf.sand       0.014963496 194.0
> veg             0.009144779 399.5
> pool            0.776755855 273.0
>
>
> On Tue, Jun 2, 2009 at 3:57 PM, stephen sefick <ssefick at gmail.com> wrote:
>>
>> 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
>>
>> ______________________________________________
>> R-help at 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.
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>



-- 
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