[R] looking for matches

Stavros Macrakis macrakis at alum.mit.edu
Mon Nov 17 21:31:07 CET 2008


I'm not sure I understand what you're looking for in the result.  What
exactly do you mean by a "match"?  What do you want in the third table
besides the class names?

Do you just want a list (not a data frame) of those class names which
table A and table B have in common?  Then how about
intersect(A$class,B$class)?

If you want to do something like a SQL join of tables A and B, where
rows are paired up based on common values of the class name, then take
a look at the "merge" function.

               -s

On Mon, Nov 17, 2008 at 3:04 PM, Alina Sheyman <alinashe at gmail.com> wrote:
> My question is probably pretty basic, but since I'm really new to R, here it
> goes ....
>
>  I have two separate data frames that include class names and various other
> information on classes. I'm trying to create a match based on class names
> and if a match exists to create a third data frame with the class name.
>
> I was hoping to accomplish this with sapply, but I can't figure out if I can
> embed an "if statement" with sapply. Does anyone know if that's a legit way
> to accomplish what I am trying to do or is there some better way?
>
> thank you,
>
> Alina Sheyman
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list