မက်ထရစ် တည်ဆောက်နိုင်သော နည်းလမ်း
Matrix (Default) & Matrix (Byrow = TRUE)
အသုံးများသော မက်ထရစ် တည်ဆောက်နည်း
Column Bind () & Row Bind
Learn 4 ways on how to build or create or construct matrix or matrices from vectors using matrix default function, another matrix function and cbind and rbind functions in R, R programming Tutorial Myanmar.
BUILD YOUR FIRST MATRIX
Hello and welcome back to WLH Education, today we are going to talk about ways to build the matrices. Let say we have the matrices or table.
How matrices table or data are created?
Data tables are originated from vectors. Vectors are put somehow into the matrices by “rbind” function.
HOW DO WE BUILD MATRICES?
We have a data how we put in a matrix in R. The very first way to do is use the “matrix()” function. This matrix() function is not used quite often and therefore it can be seen rarely. It fills the vector orderly itself depending on the number of rows and number of columns we created. The matrix function goes orderly top down as default unless you specify something in the function.
WHY not using this function?
The reason why the functon is not often used is how often are you required to take a vector and add and put into the matrix. Usually matrices arrive in different ways such as from the file or using these functions.
SECOND WAY
The second way is to use the function called “Rbind”. That is one of the most quite often seen in the real world. Rbind () takes vector of the same length and bind in a form of rows. Vectors are bound row after row from always starting from left to right. If they are not in the same length, you cannot create matrices.
THIRD WAY
The next function is “Cbind”. Vectors are bound columns after columns always starting from the top to bottom.
These are the three main ways of creating matrices, you can get one of them and explore and importing data further down the course. But if you want to create matrices in your script, these are the three main ones.
PRACTICAL SESSION
Let try to create our own matrices.
First, we are going to learn how we are going to use the “matrix()” function even though we are not using it that much.
• First run “?matrix”
• See the formula, matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE)
• Byrow = FALSE will populate the matrix column by column while Byrow = TRUE populate the matrix by column by column
Let Create some data
Let say we would like to create a vector of 20 number, using matrix by default
• data = 1:20, which will return 20 numbers starting from 1.
• Then if we want 4 rows and 5 columns of matrix, it can be written as,
• D = matrix ( data, 4, 5)
• Since by default, Byrow goes with False, the data will populate by means of up and down
Accessing Row values and Column values, and specific values
• Want the whole column can be written as, D[ , 1] which is for the whole first column
• While want for the fourth column can be performed by, D[4, ]
• Want to get specific values, index combination row [ x, y ] needs to be defined. E.g. D [ 3,4 ]
Another way of creating matrix using Byrow = TRUE
• Running the same code as above D = matrix (data, 4, 5, Byrow = TRUE)
• Where the data are populated rows by rows, going left to right this time.
RBind function
• Let create for example first three vectors
• Then we put into a form of matrix, using rbind() function
• The resulting matrix is in a form of binding vectors row by row.
CBind function
• Let create two vectors first
• Then use cbind() function
• The resulting matrix is a form of binding vectors column by column
Follow Us on Facebook:
/ wailinhtetusyd
WLH Education Channel တွင်တင်ဆက်ပြသနေသော အစီအစဉ်များ
/ @wlheducation9109
အစီအစဉ် - ၁။ Microsoft Word Basic to Advance Course
https://www.youtube.com/playlist?list...
အစီအစဉ် - ၂။ Microsoft Excel Basic to Advance Course
https://www.youtube.com/playlist?list...
အစီအစဉ် - ၃။ R-Programming for Data Science Course
https://www.youtube.com/playlist?list...
အစီအစဉ် - ၄။ Advanced Microsoft Excel (FUNCTIONS)
https://www.youtube.com/playlist?list...
အစီအစဉ် - ၅။ Finance and Accounting Analyst (Excel)
https://www.youtube.com/playlist?list...
Информация по комментариям в разработке