I have the following dataframes a, b, c
Year<-rep(c("2002","2003"),1)
Crop<-c("TTT","RRR")
a<-data.frame(Year,Crop)
Year<-rep(c("2002","2003"),2)
ProductB<-c("A","A","B","B")
b<-data.frame(Year,ProductB)
Year<-rep(c("2002","2003"),3)
Location<-c("XX","XX","YY","YY","ZZ","ZZ")
c<-data.frame(Year,Location)
and want to bring them together. When I use a function merge, I get a Cartesian product that is not what I want.
d<-merge(a,b,by="Year")
e<-merge(d,c,by="Year")
I would like the dataframe to look like
Year Crop ProductB Location
2002 TTT A XX
2002 NA B YY
2002 NA NA ZZ
2003 RRR A XX
2003 NA B YY
2003 NA NA ZZ
Is it possible? Thank you for your help.