[R] Merging two dataframes

Daniel Folkinshteyn dfolkins at gmail.com
Fri Jun 6 15:07:22 CEST 2008


try this:
FullData <- merge(ETC, SURVEY, by.x = "ord", by.y = "uid", all.x = T, 
all.y = F)

on 06/06/2008 07:30 AM Michael Pearmain said the following:
> Hi All,
> 
> Newbie question for you all but i have been looking at the archieves and the
> help dtuff to get a rough idea of what i want to do
> 
> I would like to merge two dataframes together based on a keyed variable in
> one dataframe linking to the other dataframe.  Only some of the cases will
> match but i would like to keep the others as well.
> 
> My dataframes have 67 and 28 cases respectively and i would like ot end uip
> with one file 67 cases long (all 28 are matched cases).
> 
> 
> I can use the merge command to merge two datasets together this but i still
> get some
> odd results, i'm using the code below;
> 
> ETC <- read.csv(file="CSV_Data2.csv",head=TRUE,sep=",")
> 'SURVEY <- read.csv(file="survey.csv",head=TRUE,sep=",")
> 'FullData <- merge(ETC, SURVEY, by.SURVEY = "uid", by.ETC = "ord")
> 
> The merged file seems to have 1800 cases while the ETC data file only
> has 67 and the SURVEY file only has 28.  (Reading the help it looks as if it
> merges 1 case with all cases in the other file, which is not what i want)
> 
> The matching variables fields are the 'ord' field and the 'uid' field
> Can anyone advise please?
>



More information about the R-help mailing list