[R] Function to crop p-values from multiple Anovas

Berend Hasselman bhh at xs4all.nl
Wed Mar 23 20:46:26 CET 2011


micfalb-r wrote:
> 
> 
> > p.fun <- function(arg)	{
> two_way_anova <- aov(arg  ~ age * treatment, data = example.df)
> two_way_sum <- summary(two_way_anova)
> p_values <- two_way_sum[[1]]$"Pr(>F)"[1:3]
> return(p_values)
> }
> 
> Unfortunately my setup seems to be flawed as I'm not capable to call my
> function:
> > p.fun(gene1)
> Error in eval(expr, envir, enclos) : object 'gene1' not found
> > p.fun("gene1")
> Error in model.frame.default(formula = arg ~ age * treatment, data =
> example.df,  : 
>   variable lengths differ (found for 'age')
> and provide commented, minimal, self-contained, reproducible code.
> 

Try this for your function

p.fun <- function(arg)	{   
    lhs <- get(arg, envir=as.environment(example.df))
    two_way_anova <- aov(lhs ~ age * treatment, data = example.df)
    two_way_sum   <- summary(two_way_anova)
    p_values      <- two_way_sum[[1]]$"Pr(>F)"[1:3]
    return(p_values)
} 

Use with

p.fun("gene1")

There are surely more elegant methods. E.g. no quotes in the argument of the
p.fun call.

/Berend



--
View this message in context: http://r.789695.n4.nabble.com/Function-to-crop-p-values-from-multiple-Anovas-tp3400271p3400434.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list