[R] match and %in%

Sean Davis sdavis2 at mail.nih.gov
Thu Nov 10 13:11:25 CET 2005


On 11/10/05 6:33 AM, "Luis Ridao Cruz" <Luisr at frs.fo> wrote:

> R-help,
> 
> I have two data frames with a commom column (but with different size)
> What I want is to get a column (say df1$mycolumn ) according to the
> matches of common columns in both data frames.
> 
> I have tried this but it is not working:
> 
> transform(fb, breidd = ifelse (match (as.character(df1$puntar),
> as.character(df2$puntar) )
> , df2$breidd, "no" ) ) )
> 
> transform(fb, breidd = ifelse(as.character(df1$puntar) %in%
> as.character(df2$puntar)
> , df2$breidd, "no" ) ) )


Try looking at ?merge or ?union to see if either will do what you like.

Sean




More information about the R-help mailing list