Solved

Comparing values between more than 2 datasets in R

Posted on 2014-04-25
2
205 Views
Last Modified: 2014-05-01
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
0
Comment
Question by:anajbile
2 Comments
 
LVL 1

Accepted Solution

by:
Chelsea Obrochta earned 500 total points
ID: 40023370
Hi!

You can use the merge function. For example lets say your file is named stock. Your variable are rank2(for big and small) and rank3(for top, middle, and bottom). You then do:

        merge(stock[rank2== "small",], stock[rank3== "top",])

This would give you a list of all stocks in small and top.

I hope this Helps! Let me know :)
Chelsea
0
 

Author Comment

by:anajbile
ID: 40035342
Hi Chelsea, Thank for the solution. I found that intersect function works as well.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
can finally block executed even when there is a return statement in try block 4 77
squareUp  challenge 22 132
Need an overview of CSS pre-compilation 6 63
Specific format 21 182
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now