A user has data of stock prices of weekdays of two companies GOogle and Microsoft.Now he wants to build a matrix by giving dimension of weekdays names and the company names.How to do that?
Let us assign all the stock prices to a vector
goog <- c(450,451,452,445,468)
msft <- c(230,231,232,236,228)
Now let us build a matrix
stocks <- c(goog,msft)
stock.matrix <- matrix(stocks,byrow=TRUE,nrow=2)
Now let us name the dimension
days <- c('Mon','Tue','Wed','Thu','Fri')
st.names <- c('GOOG','MSFT')
colnames(stock.matrix) <- days
rownames(stock.matrix) <- st.names
Now finally let us display the matrix
Stock.matrix
We get the following matrix
Mon Tue Wed Thu Fri
GOOG 450 451 452 445 468
MSFT 230 231 232 236 228