Starting with data from a microarray experiment and I would like to analyse the 
influence of two factors (age, treatment) on gene expression.

Looking through the r-help archives and the web I tried the following:

I put my data in a dataframe similar to this one:
> example.df <- as.data.frame(matrix(data=runif(32,100,1000), nrow=4, ncol=4))
> example.df <- 
> cbind(c("young","young","young","young","old","old","old","old"),c("drug", 
> "control", "drug","control","drug","control","drug","control"), example.df)
> colnames(example.df) <- c(c("age","treatment"),paste("gene",1:4,sep=""))
> rownames(example.df) <- paste("sample", 1:8, sep="")
> example.df
age     treatment        gene1  gene2   gene3   gene4
sample1 young    drug           392     878     908     740
sample2 young    control                167     263     711     392
sample3 young    drug           155     252     242     547
sample4 young    control                333     348     295     300
sample5 old     drug            392     878     908     740
sample6 old     control         167     263     711     392
sample7 old     drug            155     252     242     547
sample8 old     control         333     348     295     300

Now I would like to define a function that will crop the p-values from an Anova 
(so that I can use the function with a 'for loop' later on to go through all 
the genes):
> 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')

Any help on this would be truly appreciated.

Many thanks,
Mic Falb
University of Heidelberg




______________________________________________
R-help@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.

Reply via email to