如果没有可复制的数据集,您不确定您要问什么。这是一个小例子,而不是两个试验,每个试验都保存在长格式中:
set.seed(4)
test <- data.frame(test = rep(letters[1:5], 2), test_value = sample(1:100, 10, replace=TRUE))
test
test test_value
1 a 76
2 b 29
3 c 11
4 d 96
5 e 42
6 a 46
7 b 98
8 c 59
9 d 97
10 e 77
## create new indicator variable for each trial of 5 tests in this case
test$trial <- unlist(lapply(c("trial_1", "trial_2"), function(x) rep(x, 5)))
test
test test_value trial
1 a 76 trial_1
2 b 29 trial_1
3 c 11 trial_1
4 d 96 trial_1
5 e 42 trial_1
6 a 46 trial_2
7 b 98 trial_2
8 c 59 trial_2
9 d 97 trial_2
10 e 77 trial_2
##传播数据,使每个试验有5个试验,每个试验都有一个值##
library(dplyr); library(tidyr)
test %>% group_by(trial) %>% spread(test, test_value)
# A tibble: 2 x 6
# Groups: trial [2]
trial a b c d e
<chr> <int> <int> <int> <int> <int>
1 trial_1 76 29 11 96 42
2 trial_2 46 98 59 97 77
希望这会有所帮助。