[R] apply a function to loop through

Hai Lin kevinvol2002 at yahoo.com
Tue Jul 17 20:38:49 CEST 2007


Dear R users,

I have a dataset generated as follows,

myDat <- data.frame(matrix(c(rep(LETTERS[1:3],
each=5),
                             rnorm(5,mean=3,sd=0.03),
                             rnorm(5,12,1),
                             rnorm(5,1,0.5)),
                           ncol=2,
                          
dimnames=list(c(letters[1:15]),
                                        
c("tissue","Scores"))))
myDat$Grp <-c("gene1") 

There is one level "gene1" in $Grp in my data step.
I'd like to do pairwise.wilcox.test on $tissue while
going throug $Grp if there are more levels with gene2,
gene3.

I tried to loop through $Grp using apply with an error
message "Error in sort(unique.default(x), na.last =
TRUE) : 
	'x' must be atomic". 

mytry <-  apply(as.matrix(myDat),
                1,
               
function(Grp)pairwise.wilcox.test(Grp$Scores,
                                              
Grp$tissue,
                                              
p.adjust.method = "none")$p.value)     

I could not find any similar stuffs in forum. Could
anyone here give a hand?

Thanks a bunch.

kevin



More information about the R-help mailing list