[R] merging 2 frames while keeping all the entries from the "reference" frame

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Mon Apr 4 19:09:02 CEST 2011

I have my data frame "mydata" (below) and data frame "reference" -
that contains all the dates I would like to be present in the final
data frame.
I am trying to merge them so that the the result data frame contains
all 8 dates in both subgroups (i.e., Group1 should have 8 rows and
Group2 too). But when I merge it it's not coming out this way. Any
hint would be greatly appreciated!

mydata<-data.frame(mydate=rep(seq(as.Date("2008-12-29"), length = 8,
by = "week"),2),
mydata<-mydata[-out,]; dim(mydata)

# "reference" contains the dates I want to be present in the final data frame:
reference<-data.frame(mydate=seq(as.Date("2008-12-29"), length = 8, by
= "week"))

# Merging:
# my new.data contains only 7 rows in Group 1 and 4 rows in Group 2

Dimitri Liakhovitski
Ninah Consulting

More information about the R-help mailing list