Solved

Comparing values between more than 2 datasets in R

Posted on 2014-04-25
2
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The Fluent Interface Design Pattern You can use the Fluent Interface (http://en.wikipedia.org/wiki/Fluent_interface) design pattern to make your PHP code easier to read and maintain.  "Fluent Interface" is an object-oriented design pattern that r…
Introduction This question got me thinking... (http://www.experts-exchange.com/questions/28707487/GLOBALS.html) Why shouldn't we use Globals? This is a simple question without a simple answer.  How do you explain these concepts to a programmer w…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

728 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