Мы могли бы сначала вычислить сумму каждого Group
для каждого Symbol
, а затем разделить друг друга на основе значений 'MostUp'
и 'LessUp'
.
library(dplyr)
df %>%
group_by(SYMBOL, variable, Sample, IDs, Group) %>%
summarise(value = sum(value)) %>%
summarise(value = value[Group == 'MostUp']/value[Group == 'LessUp'])
# SYMBOL variable Sample IDs value
# <fct> <fct> <fct> <int> <dbl>
#1 TLR4 MMRF_2613_1_BM Baseline 2613 1.29
#2 TLR8 MMRF_2613_1_BM Baseline 2613 0.585
Для расчета t.test
между группами мы можем сделать:
df1 <- df %>%
group_by(SYMBOL, variable, Sample, IDs) %>%
summarise(value = list(t.test(value[Group == 'MostUp'],
value[Group == 'LessUp'])))
df1
# A tibble: 2 x 5
# Groups: SYMBOL, variable, Sample [2]
# SYMBOL variable Sample IDs value
# <fct> <fct> <fct> <int> <list>
#1 TLR4 MMRF_2613_1_BM Baseline 2613 <htest>
#2 TLR8 MMRF_2613_1_BM Baseline 2613 <htest>
данные
df <- structure(list(SYMBOL = structure(c(2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L), .Label = c("TLR4", "TLR8"), class = "factor"), variable = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "MMRF_2613_1_BM", class = "factor"),
value = c(3.186233, 5.471014, 2.917965, 2.147028, 7.497424,
4.16523, 7.136523, 7.96523), Sample = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L), .Label = "Baseline", class = "factor"),
IDs = c(2613L, 2613L, 2613L, 2613L, 2613L, 2613L, 2613L,
2613L), Group = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L
), .Label = c("LessUp", "MostUp"), class = "factor")),
class = "data.frame", row.names = c(NA, -8L))