[R] R command to join data.frames rows with identical keys?

Jason Rupert jasonkrupert at yahoo.com
Tue Jun 9 14:48:05 CEST 2009


I've got two data.frames and, when certain "keys" match,  I would like to add the column values from one data frame to the other data.frame.

Below I list the two data.frames, i.e. neighborhoodInfo_df, and schoolZone_df.  Based on the "address" key I would like to add the "schoolZone" key to the neighborhoodInfo_df data.frame.  

By any chance is there an R command to accomplish this in one or two steps.  I think I could do this in a "for" loop or something, but think there is might be another way in R to accomplish it smarter.  

Thanks for any info.  


neighborhoodInfo1_df<-data.frame(address<-c(101),squareFootage<-c(2000),lotsize<-c(0.75))

neighborhoodInfo2_df<-data.frame(address<-c(108),squareFootage<-c(3000), lotsize<-c(1.25))

neighborhoodInfo_df<-rbind(neighborhoodInfo1_df, neighborhoodInfo2_df)
							    
							    
schoolZone1_df<-data.frame(address<-c(101), schoolZone<-c("Sherman"))
						  
schoolZone2_df<-data.frame(address<-c(108), schoolZone<-c("Baker"))					
	  
schoolZone_df<-rbind(schoolZone1_df, schoolZone2_df)




More information about the R-help mailing list