[R] Merging two dataframes

Daniel Folkinshteyn dfolkins at gmail.com
Fri Jun 6 16:55:53 CEST 2008


cool. :) yea, the argument names are by.x and by.y, so your by.etc were 
ignored in the black hole of "arguments passed to other methods"

on 06/06/2008 09:11 AM Michael Pearmain said the following:
> Thanks
> Works perfectly.
> Was the problem due to me putting by.survey and by.etc rather than by.y 
> and by.x?
> 
> I think when i was playing around i tried the all. command in that setup 
> as well
> 
> Mike
> 
> 
> 
> On Fri, Jun 6, 2008 at 2:07 PM, Daniel Folkinshteyn <dfolkins at gmail.com 
> <mailto:dfolkins at gmail.com>> wrote:
> 
>     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?
> 
> 
> 
> 
> -- 
> Michael Pearmain
> Senior Statistical Analyst
> 
> 
> 1st Floor, 180 Great Portland St. London W1W 5QZ
> t +44 (0) 2032191684  
> mpearmain at google.com <mailto:mpearmain at google.com>
> mpearmain at doubleclick.com <mailto:mpearmain at doubleclick.com>
> 
> 
> Doubleclick is a part of the Google group of companies



More information about the R-help mailing list