[R] Getting rid of for loops

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jul 17 17:51:27 CEST 2006


On 7/17/06, Adrian DUSA <adi at roda.ro> wrote:
> Hi again,
>
> There is a slight error there, it should have been "marker2" at the fourth
> line:
> all.pairs <- combn2(5:40)
> marker1 <- names(qtl)[all.pairs[, 1]]
> marker2 <- names(qtl)[all.pairs[, 2]]
> myfun <- function(idx) {
>   summary(aov(qtl$CPP ~ qtl[,idx[1]] * qtl[,idx[2]]))[[1]]$"Pr(>F)"[3])
>   }
> p.interaction <- apply(all.pairs, 1, myfun)
>
> Actually, you don't need "as.matrix" there, just cbind all your vectors to
> obtain the final dataframe:
>
> finally <- as.data.frame(cbind(marker1, marker2, p.interaction))

or even simpler:

   finally <- data.frame(marker1, marker2, p.interaction)



More information about the R-help mailing list