我有一个这样的数据:
Response Prompt Prompt.Label Comments
1 Friend who si3 3_a
2 1 was si4_en 3_a
3 1 was si4_nag 3_a
4 Family who si3 3_b
5 1 was si4_nag 3_b
6 1 was si4_en 3_b
7 other who si3 4_a
8 1 was si4_sp 4_a
9 other who si3 4_b
10 1 was si4_en 4_b
11 Friend who si3 5_a
12 1 was si4_en 5_a
13 Family who si3 5_b
14 1 was si4_en 5_b
data<-structure(list(Response = c("Friend", "1", "1", "Family", "1",
"1", "other", "1", "other", "1", "Friend", "1", "Family", "1"
), Prompt = c("who", "was", "was", "who", "was", "was", "who",
"was", "who", "was", "who", "was", "who", "was"), Prompt.Label = c("si3",
"si4_en", "si4_nag", "si3", "si4_nag", "si4_en", "si3", "si4_sp",
"si3", "si4_en", "si3", "si4_en", "si3", "si4_en"), Comments = c("3_a",
"3_a", "3_a", "3_b", "3_b", "3_b", "4_a", "4_a", "4_b", "4_b",
"5_a", "5_a", "5_b", "5_b")), class = "data.frame", row.names = c(NA,
-14L))
我希望reshape 数据有两列,包括源和目标.当"Prompt"=="Who"时,"Source"的值应该来自"Response";如果"Comments"列的每个值的"Prompt.Label"的值都是"Prompt.Label",则"Target"应该是"Prompt.Label"的值.例如,对于第一行,Friend代表"源",si4_en代表"目标".
所需数据应为:
Source Target
1 Friend si4_en
2 Friend si4_nag
3 Family si4_nag
4 Family si4_en
5 other si4_sp
6 other si4_en
7 Friend si4_en
8 Family si4_en