[R] make a right subset!

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Thu Jul 7 13:56:50 CEST 2016


Hello, Elahe,

look at

?match

and check if

df2$Count[ match( Matched, df2$Serial)]

does what you want/need.

  Hth  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109            http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

Am 07.07.2016 um 13:34 schrieb ch.elahe via R-help:
> Hi all,
> I have 2 data frames like the following:
> the first one df1:
>
>     'data.frame':  141obs. of 1 variable:
>     $SerialNum: int 41006 41013 41044 41046 41067 41166 41202 41262 41274 41290
> and the second one df2:
>
>     'data.frame':  194 obs. of 2 variables:
>     $Serial: int   41006 41013 41018 41044 41046 41067 41111 41200 41262 41331
>     $Count : int   1 10 103 11 12 13 138 14 15 16 169 18 182 2 20 21  224 226
> then I find the intersect of two data frames in serials which is:
>
>     Matched=intersect(df1$SerialNum,df2$Serial)
> which gives me matched serials in both data frames. Next I want to get Count of these matched serials from df2 but I don't know how to make the right subset for this! Does anyone know how should I do that?
> Thanks for any help,
> Elahe
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



More information about the R-help mailing list