我想知道是否有一种方法可以合并宽格式的数据.帧(time1
,time2
,time1and2
)到一个单一的长格式的数据.帧,以实现我的Desired_output
如下?
time1 =read.table(text="
class id order ac bc
1 1 s-c 1 2
",h=TRUE)
time2 =read.table(text="
class id order ac bc
1 1 s-c 3 4
",h=TRUE)
time1and2 =read.table(text="
class id order ex1S ex2S ex1C ex2C
1 1 s-c 8 5 6 1
",h=TRUE)
Desired_output="
class id order time DV score ave_ex
1 1 s-c 1 ac 1 (8+5)/2 =6.5 # ave_ex = average of `ex`
1 1 s-c 1 bc 2 (8+5)/2 =6.5
1 1 s-c 2 ac 3 (6+1)/2 =3.5
1 1 s-c 2 bc 4 (6+1)/2 =3.5
"
1条答案
按热度按时间41zrol4v1#
一个
dplyr/tidyr
选项可以是绑定前两个表,将它们透视得更长,然后将它们与第三个表连接并进行变异:产出