Matrix After using rbind() And cbind() functionĪs above we created two matrices named MatrixB and MatrixC using two different functions rbind() and cbind() in R studio. It has been shown in the above image and we can also print the structure of MatrixC to know this as below. Here we have added a new column i.e., the 4th column with data 10, 11, and 12 using cbind() function. We shall give the name of this matrix MatrixC. Now we shall add a new column into it using cbind() function as below. We shall use the above matrix with the created name MatrixA. It will display documentation of cbind() function in R documentation as shown below. To know more about cbind() function simply type ?cbind() or help(cbind) in R. #structure of MatrixAįor adding a column to a Matrix in we use cbind() function. Here, we shall print the structure of MatrixA and MatrixB to see the difference as below. To use it we simply provide an object as its argument. The str() function in R gives the structure of an object. Step 4 - Using str() function to see the difference in both Matrices This extra one row has been added in MatrixA using rbind() function. MatrixA has 3 rows while MatrixB has 4 rows. Step 3 - Difference Between Both MatricesĪs we can see clearly the number of rows in MatrixA and MatrixB are different. Here, a new matrix named MatrixB has been created which is the combination of a new row with values 10, 11, and 12 in the previous matrix with the name MatrixA. It has been shown in the below image how it looks in R Studio. Step 1 - Creating And Printing A Matrix in R Studio #Creating a Matrix After that, we shall use rbind() function and then see the output of using rbind() function by printing again the previously created matrix. To show how to use rbind() function in R we shall first create and print a matrix. To know rbind() function in R simply type ?rbind() or help(rbind) R studio, it will give the result as below in the image. We use function rbind() to add the row to any existing matrix. In this article, we shall learn how to add rows, columns to a matrix. In a previous article, we had learned about matrices in R. It is a computing environment where statistical data may be implemented. It is also used in machine learning, data science, research, and many more new fields. R is an important programming language used heavily by statisticians.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |