user7182686
user7182686

Reputation:

Looping through all combinations of dataframes to apply a function between them

I have 6 matrices (but they are allowed to be data frames if that's easier).

I would like to perform statistical tests on all possible combinations of data frames/matrices. I prefer a "for-loop", but any apply function is welcome as well.

Let's say the t.test(x,y) function.

So: t.test(1,2), t.test(1,3), ....., t.test(5,6)

I have placed all data frames in a list and used combn() to produce all possible combinations.

From here I don't know how to proceed.

Upvotes: 1

Views: 57

Answers (1)

akrun
akrun

Reputation: 887771

We can make use of the FUN parameter from combn

lstOut <- combn(x, y, FUN = function(x) list(t.test(x[[1]], x[[2]])))
names(lstOut) <- combn(names(x), y, FUN = paste, collapse="_")

Upvotes: 1

Related Questions