Link to home
Start Free TrialLog in
Avatar of anajbile
anajbile

asked on

Comparing values between more than 2 datasets in R

Hello,

I am relatively new to R. I am amazed by how much stuff I can get done with it. Right now I am doing a project. I have a three data sets that contain the returns of the entire stocks in the S&P 500, Ranks of the book to market value of these stocks and ranks of the market capitalization of these stocks. I have divided my book to market ranks into 'top', 'bottom','middle' where 'top' represents the top 30%, 'bottom' represents the low 30% and 'middle' represents the middle 40%. The ranks of the market capitalization are divided into 'small' and 'big'.

I have to create 3 portfolios that have an intersection of 'small' and 'bottom' and then find those stocks in the return matrix. 'small' and 'top' and find the stocks in the return matrix. 'small' and 'middle' and find the stocks in the return matrix. I have to go row by row since the values of these stocks keep changing every month. So for example if one stock is 'top' one month it might be 'middle' the next month same goes for my 'small' and 'big' matrix. I have tried using the %in% function but is there a better way that I can do this without losing myself into messy code. Your help is greatly appreciated.

Thank you,
Abhishek
ASKER CERTIFIED SOLUTION
Avatar of Chelsea Obrochta
Chelsea Obrochta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of anajbile
anajbile

ASKER

Hi Chelsea, Thank for the solution. I found that intersect function works as well.