Adding a row or a column to an existing Matrix in R

Problem1:
Add a  row to an existing Matrix
Solution:
We can use the function rbind() to add a row to an existing Matrix.

From the above output, it is clear that the 4th row is added but the name for the row is missing. We need to add a new value to the Vector rownames that we defined at “Naming a Matrix“.

Problem2:

Add a  column to an existing Matrix
Solution:
We can use the function cbind() to add a column to an existing Matrix.


0

Leave a Reply

Your email address will not be published. Required fields are marked *