Q:

Different length and merge

I have two datasets (one for each population: sellers vs buyers). They are built in the same way. 
FOR BUYERS (TYPE 2)
period subject genderb gp matchp treatment type p1 p2 suminte partner
1      1         0      2    48     404      2   7  8    NA     4
1      3         1      2    48     404      2   7  8    NA     4
...

FOR SELLERS (TYPE 1)
period subject genders gp matchgp treatment type p1 p2 suminte partner
1       4        1      2    48     404       1   7  8    2     NA
...

However there are less observations in the sellers data because one seller can be matched with many buyers in one period (here, the seller interacted with 2 buyers). In the buyers data, partner indicates the subject id (column subject of the seller), while in the seller data suminte indicates the number of buyers the seller interacted with. 
What I would like to do is: in the dataset buyers, for each row add the column genders (meaning gender of seller), and matching it with the right buyer, at the right period, in the right group, matching group with the right prices... 
The outcome I'd like to have is as follows: 
FOR BUYERS (TYPE 2)
period subject genderb genders gp matchp treatment type p1 p2 suminte partner
1      1         0        1     2    48     404      2   7  8    NA     4
1      3         1        1     2    48     404      2   7  8    NA     4
...

Let me know if I am not clear enough... 

A:

# example data
df1 = read.table(text = "
                 period subject genderb gp matchgp treatment type p1 p2 suminte partner
                 1      1         0      2    48     404      2   7  8    NA     4
                 1      3         1      2    48     404      2   7  8    NA     4
                 ", header=T, stringsAsFactors=F)

df2 = read.table(text = "
                 period subject genders gp matchgp treatment type p1 p2 suminte partner
                 1       4        1      2    48     404       1   7  8    2     NA
                 ", header=T, stringsAsFactors=F)

library(dplyr)

# remove columns that exist in df1 and you won't join on them
df2 = df2 %>% select(-treatment, -type, -suminte, -partner)

# join datasets using appropriate columns
left_join(df1, df2, by=c("period","gp","matchgp","p1","p2", "partner"="subject"))

#   period subject genderb gp matchgp treatment type p1 p2 suminte partner genders
# 1      1       1       0  2      48       404    2  7  8      NA       4       1
# 2      1       3       1  2      48       404    2  7  8      NA       4       1

