I'm currently working with data.table and am attempting to merge on two tables that resemble the following:
wflanthro:
height sex l
18 1 2
18 2 2.4
19 1 3
19 2 3
20 1 3.1
20 2 3.2
21 1 4
21 2 4
22 1 5
22 2 5.1
length:
ID low.len sex
1 20 1
2 21 2
3 22 1
4 21 1
5 19 2
I want to obtain the following table from merging the two together: (notice that low.len and height are merged on each other)
ID low.len sex l
1 20 1 3.1
2 21 2 4
3 22 1 5
4 21 1 4
5 19 2 3
I have read up on the usage of by.y and by.x statements and was hoping to utilize that here, but I'm not having luck using more than 1 variable in the by.y and by.x vectors
here's what I've tried:
l_value_diff_len_gr_0<-merge(wflanthro,length,by.x=("height", "sex"), by.y=("low.len","sex"))
This errors out and does not work. I do not want to change the names of the variables formally with a setnames statement as I have to produce several tables that have the same format as above on various sets of variables, so figuring out how to merge them similarly to the code written above without changing the variable names is ideal. What am I doing wrong?