I am learning to use R for an econometrics project at the university, so forgive my n00bness
basically, using and given - a matrix "stocks prices" (rows = days, coloumns = firm's stock price) - another matrix "market capitalisation" (rows = days, coloumns= firm's market cap), I have to gather in a third matrix the prices of the shares belonging to the first quintile of the distribution of the market capitalisation for every day of observation and then I have to put the mean of the "small caps" in a fourth vector. the professor I am working for suggested me to use the quintile function, so my question is... how do I get if the "i" stock belongs to the first or the last quintile? thanks for the forthcoming help!
for (i in 1:ndays){
quantile(marketcap[i,2:nfirms],na.rm=TRUE)
for (j in 1:nfirms){
if marketcap[j,i] #BELONGS TO THE FIRST QUINTILE OF THE MARKETCAPS
thirdmatrix <- prices[i,j]
}
fourthvector[i] <- mean(thirdmatrix[i,])
}