I have two data frames with the first three columns equal, and I want to merge them. One of the data frames is bigger than the other but all the rows are related. I have:
> head(MatrixAuxiliar1)
position direction[1] direction[2] ker[1] ker[2] ker[3] ker[4]
1 2 2 1 -1 2 -2 1
2 2 2 3 -1 -2 2 1
3 2 2 5 -3 -2 2 3
4 2 2 6 -2 -1 1 2
5 2 2 7 -5 -2 2 5
6 2 2 8 -3 -1 1 3
> dim(MatrixAuxiliar1)
[1] 32 7
> head(MatrixAuxiliar2)
position direction[1] direction[2] order[1] order[2] order[3] order[4]
1 2 2 1 1 2 3 4
2 2 2 3 1 3 2 4
3 2 2 5 3 1 4 2
4 2 2 6 3 1 4 2
5 2 2 7 3 1 4 2
6 2 2 8 3 1 4 2
> dim(MatrixAuxiliar2)
[1] 300 7
The same $position and $direction always appear one time in MatrixAuxiliar1 but can appear several times (at least one) in MatrixAuxiliar2. I want that, if several rows have the same $position and $direction the resultant data frame had several rows with the same $position, $direction, and $kernel for the first data frame and different orders from the second data frame. The data frame should have 300 rows.
I tried to use the function merge but the output is a data frame with 33 rows.
> merge.data.frame(MatrixAuxiliar2,MatrixAuxiliar1,by=c(1,2,3))
position direction[1] direction[2] order[1] order[2] order[3] order[4] ker[1] ker[2] ker[3] ker[4]
1 2 2 1 1 2 3 4 -1 2 -2 1
2 2 2 3 1 3 2 4 -1 -2 2 1
3 2 2 5 3 1 4 2 -3 -2 2 1
.
.
.
32 4 9 5 1 2 3 4 -2 7 -7 2
33 4 9 5 4 1 2 3 -2 7 -7 2