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

Titus von der Malsburg malsburg at gmail.com
Tue Jun 9 15:06:29 CEST 2009



An example:

> schoolZone1_df <- data.frame(address=101, schoolZone="Sherman")
> schoolZone2_df <- data.frame(address=108, schoolZone="Baker")
> schoolZone_df <- rbind(schoolZone1_df, schoolZone2_df)
> schoolZone_df
  address schoolZone
1     101    Sherman
2     108      Baker
> neighborhoodInfo1_df <- data.frame(address=101, squareFootage=2000, lotsize=0.75)
> neighborhoodInfo2_df <- data.frame(address=108, squareFootage=3000, lotsize=1.25)
> neighborhoodInfo_df <- rbind(neighborhoodInfo1_df, neighborhoodInfo2_df)
> neighborhoodInfo_df
  address squareFootage lotsize
1     101          2000    0.75
2     108          3000    1.25
> merge(schoolZone_df, neighborhoodInfo_df, by="address")
  address schoolZone squareFootage lotsize
1     101    Sherman          2000    0.75
2     108      Baker          3000    1.25


  Titus




More information about the R-help mailing list