I'm using the edgeR package to perform pair-wise comparisons but I'm encountering problems when I try to store the results of the exactTest function as I loop through all the datasets. There are 28 comparisons to perform and at the end I would like a list containing the 28 DGEExact objects produced by exactTest.
I ran the following loop:
extest = list()
k = 1
for(i in 1:nlevels(data$samples$group)) {
for(j in (i+1):nlevels(data$samples$group)) {
if (i < nlevels(data$samples$group)) {
extest[k] = exactTest(data, pair=c(i,j))
k = k+1
}
}
}
I received the following warning for all 28 executions of exactTest():
28: In extest[k] = exactTest(data, pair = c(i, j)) :
number of items to replace is not a multiple of replacement length
The structure of the DGEExact objects is lost:
> class(extest[1])
[1] "list"
> extest[1]$comparison
NULL
The head(extest[1]) function does not work, and the whole table is printed to the screen.
I need to find a way to store the DGEExact objects as they are created, but retaining their structure and class as DGEExact.
I've already posted this question to seqanswers.com, and though one individual made considerable efforts to help, the problem remains unresolved.
I need to iterate through the DGEExact objects afterwards, and I completely agree with the viewpoints expressed here: How to name variables on the fly? Any advice would be much appreciated, as I'm sure this is a fundamental problem of handling R data types which could help many users out there.