[R] make a right subset!
Ulrik Stervbo
ulrik.stervbo at gmail.com
Thu Jul 7 13:59:34 CEST 2016
Hi Elahe,
Use subset and the %in% operator:
subset(df2, Serial %in% Matched)[["Count "]]
Best wishes,
Ulrik
On Thu, 7 Jul 2016 at 13:37 ch.elahe via R-help <r-help at r-project.org>
wrote:
> 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list