- 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 print matrix without line numbers in R?
To print matrix without line numbers in R, we can follow the below steps −
First of all, create a matrix.
Then, print the matrix with as.data.frame and row.names argument set to FALSE.
Example1
Create the matrix
Let’s create a matrix as shown below −
M1<-matrix(rpois(60,5),ncol=3) M1
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
Output
[,1] [,2] [,3] [1,] 9 4 2 [2,] 3 4 7 [3,] 3 3 4 [4,] 3 9 8 [5,] 4 3 7 [6,] 6 8 5 [7,] 9 5 3 [8,] 2 1 6 [9,] 1 8 7 [10,] 8 3 5 [11,] 3 6 5 [12,] 8 4 5 [13,] 6 6 4 [14,] 2 3 2 [15,] 3 5 3 [16,] 5 11 7 [17,] 4 4 7 [18,] 2 4 4 [19,] 4 7 4 [20,] 6 5 7
Removing line numbers from the matrix
Using as.data.frame function and print function to print the matrix M1 without line numbers −
M1<-matrix(rpois(60,5),ncol=3) print(as.data.frame(M1),row.names=F)
Output
V1 V2 V3 9 4 2 3 4 7 3 3 4 3 9 8 4 3 7 6 8 5 9 5 3 2 1 6 1 8 7 8 3 5 3 6 5 8 4 5 6 6 4 2 3 2 3 5 3 5 11 7 4 4 7 2 4 4 4 7 4 6 5 7
Example 2
Create the matrix
Let’s create a matrix as shown below −
M2<-matrix(round(rnorm(80),1),ncol=4) M2
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
Output
[,1] [,2] [,3] [,4] [1,] -0.7 0.9 0.3 -0.6 [2,] -1.0 -0.8 0.6 -1.3 [3,] -1.9 -1.2 -1.9 -0.8 [4,] -1.8 0.7 -1.7 -1.0 [5,] -2.1 -0.3 1.6 0.8 [6,] -1.1 -0.9 -1.7 -1.9 [7,] -0.1 1.5 -1.2 0.2 [8,] 0.5 -0.9 0.0 -0.3 [9,] 0.3 2.1 -0.2 1.0 [10,] 1.3 0.2 -0.6 0.5 [11,] -0.5 1.2 -0.8 -0.9 [12,] -1.7 -1.0 0.6 -0.2 [13,] 1.0 0.3 0.8 -0.1 [14,] -0.1 1.9 -2.3 -0.3 [15,] -0.5 -1.3 0.1 -0.7 [16,] 1.3 1.0 0.8 -0.5 [17,] 1.2 -0.4 2.4 0.3 [18,] 0.9 -1.1 0.4 -1.5 [19,] 0.6 -0.7 -2.7 1.1 [20,] -1.4 -0.5 0.5 -0.4
Removing line numbers from the matrix
Using as.data.frame function and print function to print the matrix M1 without line numbers −
M2<-matrix(rpois(80,1),ncol=4) print(as.data.frame(M1),row.names=F)
Output
V1 V2 V3 V4 -0.7 0.9 0.3 -0.6 -1.0 -0.8 0.6 -1.3 -1.9 -1.2 -1.9 -0.8 -1.8 0.7 -1.7 -1.0 -2.1 -0.3 1.6 0.8 -1.1 -0.9 -1.7 -1.9 -0.1 1.5 -1.2 0.2 0.5 -0.9 0.0 -0.3 0.3 2.1 -0.2 1.0 1.3 0.2 -0.6 0.5 -0.5 1.2 -0.8 -0.9 -1.7 -1.0 0.6 -0.2 1.0 0.3 0.8 -0.1 -0.1 1.9 -2.3 -0.3 -0.5 -1.3 0.1 -0.7 1.3 1.0 0.8 -0.5 1.2 -0.4 2.4 0.3 0.9 -1.1 0.4 -1.5 0.6 -0.7 -2.7 1.1 -1.4 -0.5 0.5 -0.4
- Related Articles
- How to print a factor vector without levels in R?
- How to create correlation matrix plot without variables labels in R?
- How to create a matrix without column and row indices in R?
- How to print a large number of values in R without index?
- How to remove line numbers from data.table object in R?
- Swift Program to Print Matrix numbers containing in Z form
- How will you print numbers from 1 to 100 without using loop in C?
- How to extract diagonal elements of a matrix in R without using diag function?
- Print numbers in matrix diagonal pattern in C Program.
- How to print without newline in Python?
- Program to print numbers from 1 to 100 without using loop
- C Program to print numbers from 1 to N without using semicolon
- How to print new line in Java?
- Print 2D matrix in different lines and without curly braces in C/C++
- How to convert a matrix to binary matrix in R?

Advertisements