-2

I have the following matrix:

matrix

I want to create 2 new matrix for the companies! with the company code as distribution key.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • 2
    Don't post pictures of data. See [how to create a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It's best to give the explicit desired output for the sample input. – MrFlick Mar 13 '17 at 19:31

1 Answers1

0

Like @MrFlick said, no pictures of data; rather use a minimal example like this:

df <- data.frame(Company = c(1, 1, 1, 2, 2, 2), v1 = c(1, 2, 3, 1, 2, 2), v2 = c(2, 2, 4, 2, 2, 1), v3 = c(1, 1, 1, 3, 1, 1))

To come back to your problem, subsetis perfectly suited for this:

comp1 <- subset(df, Company == 1)
comp2 <- subset(df, Company == 2)
mb-beep
  • 60
  • 1
  • 9
  • Thank you guys! You are awesome ! Now the trick is that I have 206 stocks with daily stock prices, outstanding debt and the risk free rate (for up to 25 years). All in a big dataframe/matrix (total observations of 650.000) So, i want to apply some calculations / functions to every 206 dataframe/matrix. (I have all the functions coded) Can you help me out? maybe with a for loop or apply function? – Oliver Langkilde Sonne Mar 14 '17 at 21:21