[R] Select the rows in a dataframe that matches a criteria in another dataframe

Cecilia Carmo cecilia.carmo at ua.pt
Sun May 10 23:52:52 CEST 2009


Hi everyone! Thank you for the help you have been given to 
me, and here I'm with another problem with my dataframes:
  
I have two dataframes (with much more observations), like 
these:
Dataframe1
Firm         Year      cash
500400200    2007     100
500400200    2006     200
500400200    2005     400
500400300    2007     300
500400300    2006     240
500400300    2005     120
500400400    2007     340
500400400    2006     890
500400400    2005     250

Dataframe 2
Firm            Audited     consolidate
500400200     yes           no
500400300     yes          yes
500400400     no            no

I want to make another dataframe equal to the dataframe1, 
but just with the firms «audited», or with the firms 
«audited» and «consolidate». For example, with the audited 
and consolidated, the output would be just firm 500400300, 
like this:
Firm         Year      cash
500400300    2007     300
500400300    2006     240
500400300    2005     120

I’ve tried intersect () but it gives me just the number of 
the firm, and it is not what I want. What I want is a 
dataframe with all the information, but just the firms 
that match my criteria.

Could anyone help me with another function?

Thank you in advance,

Cecília Carmo (Portugal)




More information about the R-help mailing list