I have run a kruskal.test() using the by() function, which returns a list of results like the following (subset of results): Herb.df$ID: 4-2 Kruskal-Wallis chi-squared = 18.93, df = 7, p-value = 0.00841 -------------------------------------------------------------------- Herb.df$ID: 44-1 Kruskal-Wallis chi-squared = 4.43, df = 6, p-value = 0.6187 So then, how do extract a vector of p-values (i.e., result$p.value) for every element in the list? -- View this message in context: http://n4.nabble.com/Extracting-values-from-a-list-tp1560701p1560701.html Sent from the R help mailing list archive at Nabble.com.
chipmaney schreef:> I have run a kruskal.test() using the by() function, which returns a list of > results like the following (subset of results): > > Herb.df$ID: 4-2 > Kruskal-Wallis chi-squared = 18.93, df = 7, p-value = 0.00841 > -------------------------------------------------------------------- > Herb.df$ID: 44-1 > Kruskal-Wallis chi-squared = 4.43, df = 6, p-value = 0.6187 > > > So then, how do extract a vector of p-values (i.e., result$p.value) for > every element in the list? > > > >If result$p.value normally returns the p value from a kruskal.test result you can probably do something like: vector_pvalues = sapply(result_from_by_list, function(x) x$p.value) cheers, Paul
Try this: sapply(x, '[', 'p.value') On Thu, Feb 18, 2010 at 5:21 PM, chipmaney <chipmaney at hotmail.com> wrote:> > I have run a kruskal.test() using the by() function, which returns a list of > results like the following (subset of results): > > Herb.df$ID: 4-2 > ? ? ? Kruskal-Wallis chi-squared = 18.93, df = 7, p-value = 0.00841 > -------------------------------------------------------------------- > Herb.df$ID: 44-1 > ? ? ? ?Kruskal-Wallis chi-squared = 4.43, df = 6, p-value = 0.6187 > > > So then, how do extract a vector of p-values (i.e., result$p.value) for > every element in the list? > > > > -- > View this message in context: http://n4.nabble.com/Extracting-values-from-a-list-tp1560701p1560701.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O