- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create an empty matrix in R?
An empty matrix can be created in the same way as we create a regular matrix in R but we will not provide any value inside the matrix function. The number of rows and columns can be different and we don’t need to use byrow or bycol argument while creating an empty matrix because it is not useful since all the values are missing. In R, one column is created by default for a matrix, therefore, to create a matrix without a column we can use ncol =0.
Example
> M1<-matrix(,nrow=10) > M1 [,1] [1,] NA [2,] NA [3,] NA [4,] NA [5,] NA [6,] NA [7,] NA [8,] NA [9,] NA [10,] NA > M2<-matrix(,nrow=10,ncol=0) > M2 [1,] [2,] [3,] [4,] [5,] [6,] [7,] [8,] [9,] [10,] > M3<-matrix(,nrow=10,ncol=10) > M3 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] NA NA NA NA NA NA NA NA NA NA [2,] NA NA NA NA NA NA NA NA NA NA [3,] NA NA NA NA NA NA NA NA NA NA [4,] NA NA NA NA NA NA NA NA NA NA [5,] NA NA NA NA NA NA NA NA NA NA [6,] NA NA NA NA NA NA NA NA NA NA [7,] NA NA NA NA NA NA NA NA NA NA [8,] NA NA NA NA NA NA NA NA NA NA [9,] NA NA NA NA NA NA NA NA NA NA [10,] NA NA NA NA NA NA NA NA NA NA > M4<-matrix(,nrow=10,ncol=3) > M4 [,1] [,2] [,3] [1,] NA NA NA [2,] NA NA NA [3,] NA NA NA [4,] NA NA NA [5,] NA NA NA [6,] NA NA NA [7,] NA NA NA [8,] NA NA NA [9,] NA NA NA [10,] NA NA NA > M5<-matrix(,nrow=3,ncol=10) > M5 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] NA NA NA NA NA NA NA NA NA NA [2,] NA NA NA NA NA NA NA NA NA NA [3,] NA NA NA NA NA NA NA NA NA NA Editing an empty matrix: > M3[1,1]<-1 > M3[2,2]<-1 > M3[3,3]<-1 > M3[4,4]<-1 > M3[5,5]<-1 > M3[6,6]<-1 > M3[7,7,]<-1 > M3[7,7]<-1 > M3[8,8]<-1 > M3[9,9]<-1 > M3[10,10]<-1 > M3 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 NA NA NA NA NA NA NA NA NA [2,] NA 1 NA NA NA NA NA NA NA NA [3,] NA NA 1 NA NA NA NA NA NA NA [4,] NA NA NA 1 NA NA NA NA NA NA [5,] NA NA NA NA 1 NA NA NA NA NA [6,] NA NA NA NA NA 1 NA NA NA NA [7,] NA NA NA NA NA NA 1 NA NA NA [8,] NA NA NA NA NA NA NA 1 NA NA [9,] NA NA NA NA NA NA NA NA 1 NA [10,] NA NA NA NA NA NA NA NA NA 1
- Related Articles
- How to create an empty data frame in R?
- How to create an empty plot using ggplot2 in R?
- How to create an image of matrix of pixels in R?
- How to create matrix diagram in R?
- How to create empty bar plot in base R?
- How to create an upper triangular matrix using vector elements in R?
- How to create a sparse matrix in R?
- How to create correlation matrix plot in R?
- How to create a covariance matrix in R?
- How to create an empty VIEW in MySQL?
- How to create an empty list in Python?
- How to create an empty dictionary in Python?
- How to create an empty tuple in Python?
- How to create an empty class in Python?
- How to create an empty array in Kotlin?

Advertisements