For RNA-seq you generally want biological replicates as opposed to technical replicates. That being said, there are a few things that you need to change.
Example data.
df <- structure(list(temp = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = c("t8", "t80"), class = "factor"), Test = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("T1", "T2", "T3", "T4"
), class = "factor"), Sample = 1:24, GeneI = c(55L, 89L, 54L,
453L, 50L, 32L, 45L, 45L, 50L, 54L, 45L, 15L, 43L, 25L, 404L,
385L, 51L, 32L, 454L, 395L, 53L, 35L, 96L, 87L), GeneII = c(204,
200, 44, 212, 299, 405, 79, 291, 303, 259, 207, 255, 99, 226,
206, 316, 80, 126, 131, 186, 478, 451, 323, 185)), row.names = c(NA,
-24L), class = "data.frame")
First, the matrix should be genes as rows, and samples as columns.
library("tidyverse")
mat <- df %>%
select(-temp, -Test) %>%
mutate(Sample = str_c("sample_", Sample)) %>%
column_to_rownames("Sample") %>%
t %>%
as.matrix
> mat[, 1:5]
sample_1 sample_2 sample_3 sample_4 sample_5
GeneI 55 89 54 453 50
GeneII 204 200 44 212 299
You then want a group data.frame.
groups <- df %>%
select(temp, Test, Sample) %>%
mutate(Sample = str_c("sample_", Sample)) %>%
column_to_rownames("Sample")
> head(groups, 5)
temp Test
sample_1 t80 T1
sample_2 t80 T1
sample_3 t80 T1
sample_4 t80 T1
sample_5 t80 T1
If you want to sum the technical replicates, You can then do so after creating the DGEList object using the above matrix and data.frame as inputs. I'm assuming Test denotes the technical replicates?
dge <- DGEList(mat, samples=groups)
dge <- sumTechReps(dge, dge$samples$Test)
> dge
An object of class "DGEList"
$counts
T1 T2 T3 T4
GeneI 733 254 940 1120
GeneII 1364 1394 1053 1754
$samples
group lib.size norm.factors temp Test
T1 1 2097 1 t80 T1
T2 1 1648 1 t80 T2
T3 1 1993 1 t8 T3
T4 1 2874 1 t8 T4
Alternatively, instead of summing the technical replicates, you can add it to the regression model to account for it when building the design matrix.
design <- model.matrix(~ temp + Test, groups)