I am having 2 data frames in the below format:
dt1
id col1 col2 col3 col4
___ ____ ____ _____ _____
1 2 3 1 2
2 3 4 1 1
3 1 1 1 1
4 1 2 1 2
5 1 1 1 1
6 1 2 1 2
dt2
id col1 col2 col3 col4
___ ____ ____ _____ _____
1 1 3 1 2
2 3 4 1 0
4 1 1 1 1
6 1 2 1 2
9 2 1 1 1
12 1 2 1 2
and I want to aggregate and combine these two data frames by the id and the resulting dataframe like
dt3
id col1 col2 col3 col4
___ ____ ____ _____ _____
1 3 6 2 4
2 6 8 2 1
3 1 1 1 1
4 2 3 2 3
5 1 1 1 1
6 2 4 2 4
9 2 1 1 1
12 1 2 1 2
I tried with dt3=merge(dt1,dt2,all=TRUE)
but did not work.Also tried dt3=merge(dt1,dt2,by=id)
too did not work.Any help is appreciated.