Re: [R] how to combine two data frames via factors (or somehow else)

From: Sarah Goslee <sarah.goslee_at_gmail.com>
Date: Sun, 29 May 2011 17:11:08 -0400

merge() should do the trick. Using strings instead of factors works better, though.

Sarah

On Sun, May 29, 2011 at 4:51 PM, Philipp Chapkovski <chapkovski_at_gmail.com> wrote:
> Hello!
> The question should be very naive, but I am a beginner and stuck with
> this unfortunately.
> There is a dataset of people's affiliation to companies that looks
> like that (a data frame actually)
>  x y
> 1 a X
> 2 b X
> 3 c X
> 4 f Z
> 5 e Z
> 6 g Z
> where x is a name of a person and y is a company name. That is, a,b,c
> work in a company X. f,e,g work in a company Z.
>
> and there is another dataset with the affiliation of companies. Like
> that (much much longer in reality):
>  y1 y2
> 1  X W
> 2  Z W
> that means that both X and Z belongs to the same company W.
> What is the most compact way (without loops etc) to 'attach' the 'head
> company' from the second dataset to the first dataset so I can have
> something like:
>
>  x  y owner
> 1 a X W
> ...
> 4 f  Z W
>
> I know it should be done somehow with factors, but I don't know how.
> Thank you in advance!
>

-- 
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
R-help_at_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.
Received on Sun 29 May 2011 - 21:12:44 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 29 May 2011 - 21:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive