So let's say I have a data frame with X and Y variables and Z1, Z2 and Z3 subjects like this:
> df <- data.frame(X=c(0,0,1,1), Y=c(0,1,0,1), Z1=c(4,8,1,2), Z2=c(7,2,4,1), Z3=c(5,2,0,1))
> df
X Y Z1 Z2 Z3
1 0 0 4 7 5
2 0 1 8 2 2
3 1 0 1 4 0
4 1 1 2 1 1
What I want to do is to put all results in one column Z and therefore have a dataframe that looks like this:
X Y Z
1 0 0 4
2 0 1 8
3 1 0 1
4 1 1 2
5 0 0 7
6 0 1 2
7 1 0 4
8 1 1 1
9 0 0 5
10 0 1 2
11 1 0 0
12 1 1 1
What is the easiest way to do this? Note that there may be more than 3 subjects.