Have a look at the merge function.

  "Merge two data frames by common columns or row names, or do other
     versions of database _join_ operations."


  Titus

On Tue, Jun 09, 2009 at 05:48:05AM -0700, Jason Rupert wrote:
> 
> 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)
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to