Skip to content
Prev 255902 / 398506 Next

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

Thanks a lot - these solutions are much more elegant than my own:

new.data<-merge(mydata[mydata$group %in%
levels(mydata$group)[1],],reference,by="mydate",all.x=T,all.y=T)
new.data[["group"]][is.na(new.data[["group"]])]<-levels(mydata$group)[1]
new.data[["values"]][is.na(new.data[["values"]])]<-0

# Continue Merging - starting with Group2:
for(i in 2:nlevels(mydata$group)){  #i<-2
	temp<-merge(mydata[mydata$group %in%
levels(mydata$group)[i],],reference,by="mydate",all.x=T,all.y=T)
	temp[["group"]][is.na(temp[["group"]])]<-levels(mydata$group)[i]
	temp[["values"]][is.na(temp[["values"]])]<-0
	new.data<-rbind(new.data,temp)
}

Dimitri
On Mon, Apr 4, 2011 at 3:07 PM, Henrique Dallazuanna <wwwhsd at gmail.com> wrote: